Listbox

  • Thread starter Thread starter Peter Morris
  • Start date Start date
P

Peter Morris

In vbCode how do I set a listbox so that a particular
row is selected , eg the first row, whatever the value
is.
 
Assuming that the listbox is set to single select mode:
Me.ListBoxName.Value =
Me.ListBoxName.ItemData(0-Me.ListBoxName.ColumnHeads)
 
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.

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