18

How can I retrieve the value of specified column of the selected row in a multicolumn listbox?

I populate the listbox by setting the RowSource property with a SQL string. BoundColumn set to value 1.

I can retrieve the value of the bound column (of the selected row) by using ListBox.Value. But I also want the value of another column.

waanders
  • 8,907
  • 22
  • 70
  • 102

3 Answers3

23

Use listboxControl.Column(intColumn,intRow). Both Column and Row are zero-based.

RolandTumble
  • 4,633
  • 3
  • 32
  • 37
  • 8
    I think you need to beef that up a little to get currently selected items in a multiselect list box, say: `For Each itm In Me.List0.ItemsSelected` .. `s = s & vbCrLf & Me.List0.Column(1, itm)` .. `Next` .. `MsgBox s` – Fionnuala Jan 10 '11 at 18:15
  • 1
    @Remou--you're absolutely correct. In fact, the code in my current project does exactly that--but the OP's question used the definite article, which I read as implying one selected row. Also--I'm sure you know this, but for anyone else reading, keep in mind that `itm` in your example must be `Variant`. – RolandTumble Jan 10 '11 at 18:30
  • 2
    Yes, I meant one selected row, so `listboxControl.Column(intColumn)` works fine for me. Thanks – waanders Jan 11 '11 at 10:27
15

Just a little addition. If you've only selected 1 row then the code below will select the value of a column (index of 4, but 5th column) for the selected row:

me.lstIssues.Column(4)

This saves having to use the ItemsSelected property.

Kristian

Kristian
  • 406
  • 4
  • 12
  • 1
    Thank you very much. This is the perfect code if you are looking for Current Selected row in ListBox. +1 – Pankaj Jan 28 '17 at 18:38
2

For multicolumn listbox extract data from any column of selected row by

 listboxControl.List(listboxControl.ListIndex,col_num)

where col_num is required column ( 0 for first column)