Retrieve column values of the selected row of a multicolumn Access listbox
Asked Answered
C

3

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.

Colostomy answered 10/1, 2011 at 16:29 Comment(0)
C
23

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

Crossfertilize answered 10/1, 2011 at 18:4 Comment(3)
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 sJamila
@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.Crossfertilize
Yes, I meant one selected row, so listboxControl.Column(intColumn) works fine for me. ThanksColostomy
C
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

Campus answered 28/3, 2014 at 15:1 Comment(1)
Thank you very much. This is the perfect code if you are looking for Current Selected row in ListBox. +1Bourbonism
V
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)

Volition answered 16/9, 2014 at 8:16 Comment(1)
I think you meant listboxControl.Column(col_num, listboxControl.ListIndex)Bouzoun

© 2022 - 2024 — McMap. All rights reserved.