Selected listbox item

F

fi.or.jp.de

Hi All,

I have listbox having six columns for each row.
I need to know which item is been selected ( six columns item ).
 
J

Joel

Use List Index. You can only select one row so you can't tell which column
that is selected. This doesn't work with multi-select option. The index
number starts with zero.
 
T

Tim Zych

Another way is to use the Selected property, which works for all MultiSelect
settings, whether Single, Multi or Extended.

Dim n As Long
With Me.ListBox1
For n = 0 To .ListCount - 1
If .Selected(n) = True Then
MsgBox .List(n, 0) ' First column, selected row(s)
End If
Next
End With

The List property is zero-based, so List(n,0) is the 1st column, List(n,1)
is the 2nd column. The row selection is zero-based too, so List(1,0) is the
2nd row, 1st column. Read more about this in VBA help: "List Property
(Forms)" and "Selected Property (Forms)".
 

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