P Peter Morris Sep 9, 2005 #1 In vbCode how do I set a listbox so that a particular row is selected , eg the first row, whatever the value is.
In vbCode how do I set a listbox so that a particular row is selected , eg the first row, whatever the value is.
K Ken Snell [MVP] Sep 9, 2005 #2 Assuming that the listbox is set to single select mode: Me.ListBoxName.Value = Me.ListBoxName.ItemData(0-Me.ListBoxName.ColumnHeads)
Assuming that the listbox is set to single select mode: Me.ListBoxName.Value = Me.ListBoxName.ItemData(0-Me.ListBoxName.ColumnHeads)
D Dirk Goldgar Sep 9, 2005 #3 Peter Morris said: In vbCode how do I set a listbox so that a particular row is selected , eg the first row, whatever the value is. Click to expand... If the listbox is not multiselect, you can select the first data row like this: With Me!lstMyListBox .Value = .ItemData(Abs(.ColumnHeads)) End With If you know the list box has its ColumnHeads property set to no, you can just write: With Me!lstMyListBox .Value = .ItemData(0) End With If the list box is multiselect, then you can't set its value, so you have to do it like this: With Me!lstMyListBox .Selected (Abs(.ColumnHeads)) = True End With But again, if you know it has no column headers, you can simplify that to Me!lstMyListBox.Selected (0) = True
Peter Morris said: In vbCode how do I set a listbox so that a particular row is selected , eg the first row, whatever the value is. Click to expand... If the listbox is not multiselect, you can select the first data row like this: With Me!lstMyListBox .Value = .ItemData(Abs(.ColumnHeads)) End With If you know the list box has its ColumnHeads property set to no, you can just write: With Me!lstMyListBox .Value = .ItemData(0) End With If the list box is multiselect, then you can't set its value, so you have to do it like this: With Me!lstMyListBox .Selected (Abs(.ColumnHeads)) = True End With But again, if you know it has no column headers, you can simplify that to Me!lstMyListBox.Selected (0) = True