Selecting Listbox item

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?
 
K

Ken Snell

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.
 
J

JonWayn

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.
 
K

Ken Snell

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top