Selecting Listbox item

  • Thread starter Thread starter JonWayn
  • Start date Start date
J

JonWayn

Whenever I use the Selected property to select a listbox item, the item is
selected visually, however, if I try to read the listbox's value (which i
suppose is the default property), I get a null. How then do you select an
item so that the value property returns the data in that item?
 
Is the listbox a multiselect listbox? If yes, such a box will always return
Null as its value (see Help file).

If it's not a multiselect listbox, then use the ListIndex property to select
the item in the listbox:

Me.ListBoxName.ListIndex = X

where X is the row number minus 1 (row is a zero-based property) that you
want to select.
 
That is a ReadOnly property


Ken Snell said:
Is the listbox a multiselect listbox? If yes, such a box will always return
Null as its value (see Help file).

If it's not a multiselect listbox, then use the ListIndex property to select
the item in the listbox:

Me.ListBoxName.ListIndex = X

where X is the row number minus 1 (row is a zero-based property) that you
want to select.
 
It's read only if the list box does not have the focus. You can set it if
the listbox has the focus.

If the list box doesn't have the focus, then you can use the Selected
property to set the listbox to a specific item:
Me.ListBoxName.Selected(x) = True
where x is the row number minus 1 of the item to be selected.
 
Back
Top