I have a three-column list box that displays the search results. Is there a way to highlight the first row in list box by default?
Thanks for any help in advance.
If you want to select the first row of a Listbox irespective of the value of the first row you can use:
lstMyListBox.Selected(0) = True
If you want to select a specific row based on a LISTBOX or COMBO BOX 'value' then the following will work:
This will work if you know the value of the first record:
Using Combo box 'cboIdStatus'
First row value of '0'
Placed in Forms ONLOAD event
Private Sub Form_Load()
Dim Myint As Integer
Myint = 0
Me.cboIdStaus = Myint
'if required additional code to query or run code based on the selection
End Sub
You can adopt to run from any event you want, you can also adopt it to select any other known listbox or combobox value. The above is useful for selecting a value when a form is loaded
For some off reason, mine worked (and succesfully selected the first item in the list box) when I changed the code to:
Code:
lstReference.Selected(1) = True
Not sure why or how or whatever... but the 0 wasn't working for me... or it was selecting some random record in big lists. Anyhoo... try it... might work for you as well as it did for me.