List Boxes

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

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
 
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.
 
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
 
Back
Top