Position to a row in a list box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can you programmatically position a list box to a particular row. For
example, if I want the 100th row to be at the top of the list box, how can I
do this? Thanks in advance.
 
Make a table for list box choices... If you REALLY want to snaz it up add a
field called ListBoxType to store the name of the list box and put several
entries in a table. Add a text field for entries, and an numeric (long) field
for the order.

example table

ListBoxType TextValue Order
-------------------------------------------------------
TRAFFIC_LIGHT Yellow 2
TRAFFIC_LIGHT Green 1
TRAFFIC_LIGHT Red 3
PROJ_PRIORITIES Low 1
PROJ_PRIORITIES Medium 2
PROJ_PRIORITIES High 3

This is a GREAT tool because you can use the table to populate list boxes on
any form and changing the values doesn't involve going to each form it is on.

For me it lets me let the users be responsible for their own data (Build
them a form to manage list box choices via this table.
 
See:
http://www.lebans.com/List_Combo.htm#ScrollListbox

Raw NewsGroup Postings

Scroll a ListBox to a specific row

Arrow keys to navigate a ListBox without the Focus

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


Method #2



--

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