How to get selected value in multicolumn listbox

后端 未结 4 1724
长发绾君心
长发绾君心 2020-12-06 21:25

I have a multicolumn listbox in my userform and I would like to get all the values of the elements which are in the selected row in the listbox.

Here is my userform:

4条回答
  •  不知归路
    2020-12-06 22:20

    With a single column you can retrieve the value as below:

    Dim str as String
    str = me.ListBox1.Value
    

    With a multicolumn you can retrieve the value like this:

    Dim strCol1 as String
    Dim strCol2 as String
    Dim strCol3 as String
    strCol1 = ListBox1.List(0, 1)
    strCol2 = ListBox1.List(0, 2)
    strCol3 = ListBox1.List(0, 3)
    

    or you can add all the data into 1 String:

    Dim strColumns as String
    strColumns = ListBox1.List(0, 1) + " " + ListBox1.List(0, 2) + " " + ListBox1.List(0, 3)
    

提交回复
热议问题