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
 

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

Back
Top