Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

List Boxes

55 views
Skip to first unread message

Steve

unread,
Jul 7, 2004, 5:18:32 AM7/7/04
to
With a list box having many entries, I can select a row as Selected but is
there a way to move that row into the visble portion of the list box. That
is if I make the last row Selected in code how do you move the last row so
that it can be seen in the list rather than having to manually use the
scroll bar to move it up?

Any hints would be appreciated.

Steve


Wayne Morgan

unread,
Jul 7, 2004, 5:52:02 AM7/7/04
to
Stephen Lebans has an example here. The part about listboxes starts part way
down the page.

http://www.lebans.com/SelectRow.htm

--
Wayne Morgan
MS Access MVP


"Steve" <stephe...@dhl.com> wrote in message
news:%23ha6wNA...@tk2msftngp13.phx.gbl...

Steve

unread,
Jul 7, 2004, 6:27:45 AM7/7/04
to
Thanks for that, used it to do what I wanted.

"Wayne Morgan" <comprev_gothro...@hotmail.com> wrote in message
news:Ou1RPgAZ...@TK2MSFTNGP11.phx.gbl...

Stephen Lebans

unread,
Jul 7, 2004, 3:50:33 PM7/7/04
to
Actually Wayne, a far simpler solution is here:

http://www.lebans.com/List_Combo.htm#ScrollListbox
Scroll a ListBox to a specific row. Emulates the VB ListBox TopIndex
property. You can alter the code to easily have the selected row display
as the first or last row as well. The example code is placed behind a
Command Button.

' *** CODE START
Private Sub cmdListIndex_Click()
On Error GoTo Err_cmdListIndex_Click

' Always make NumRows an odd number
' if you want selected Row to be in the
' middle of the ListBox.

' NumRows is the number of completely visible rows in the ListBox Const
NumRows = 7
' Row we want displayed in middle of ListBox.
Dim intDesiredRow As Integer

' Arbitrarily select the 24th row.
intDesiredRow = 24
' ListBox must have the Focus
Me.List2.SetFocus
' Force ListBox to start from the top
Me.List2.ListIndex = 1

' Force the Scroll offset we desire
Me.List2.ListIndex = intDesiredRow + (NumRows / 2)
' Now select the row without further scrolling
Me.List2.ListIndex = intDesiredRow

Exit_cmdListIndex_Click:
Exit Sub

Err_cmdListIndex_Click:
MsgBox Err.Description
Resume Exit_cmdListIndex_Click

End Sub
' ***CODE END

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


"Wayne Morgan" <comprev_gothro...@hotmail.com> wrote in
message news:Ou1RPgAZ...@TK2MSFTNGP11.phx.gbl...

Wayne Morgan

unread,
Jul 7, 2004, 8:03:25 PM7/7/04
to
Thanks Stephen,

I'll take a look at that one also.

--
Wayne Morgan
MS Access MVP


"Stephen Lebans" <ForEmailGotoMy.WebSit...@linvalid.com>
wrote in message news:eB0XJtF...@tk2msftngp13.phx.gbl...

Steve

unread,
Jul 8, 2004, 10:42:49 AM7/8/04
to
Thanks for all the help, this method helped me to do something that was not
quite the same as my original problem, everything works as it should now.

Steve

"Stephen Lebans" <ForEmailGotoMy.WebSit...@linvalid.com>
wrote in message news:eB0XJtF...@tk2msftngp13.phx.gbl...

0 new messages