如何在多列列表框中获取选定的值 [英] How to get selected value in multicolumn listbox

查看:363
本文介绍了如何在多列列表框中获取选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用户窗体中有一个多列列表框,我想获取列表框中所选行中所有元素的值.

这是我的用户窗体:

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:


就像在照片中一样,我想选择一行,然后单击按钮Associer,可以获得该行的信息.我只需要获取第一列,即CAN20168301436,我想从整行中获取信息.
我该怎么做?
这是我单击按钮的事件:


Just like in the photo, I want to select one line then I will click button Associer and I could get the information of this row. I can just get the first column which is CAN20168301436 I want to get the information from the whole line.
How can I do it?
Here is my button clicked event:

Private Sub CommandButton3_Click()
   a = ListBoxResultatFind.Text
End Sub

推荐答案

您可以使用此代码

Private Sub CommandButton3_Click()
    Dim strng As String
    Dim lCol As Long, lRow As Long

    With Me.ListBox1 '<--| refer to your listbox: change "ListBox1" with your actual listbox name
        For lRow = 0 To .ListCount - 1 '<--| loop through listbox rows
            If .selected(lRow) Then '<--| if current row selected
                For lCol = 0 To .ColumnCount - 1 '<--| loop through listbox columns
                    strng = strng & .List(lRow, lCol) & " | " '<--| build your output string
                Next lCol
                MsgBox "you selected" & vbCrLf & Left(strng, (Len(strng) - 1)) '<--| show output string (after removing its last character ("|"))
                Exit For '<-_| exit loop
            End If
        Next lRow
    End With
End Sub

这篇关于如何在多列列表框中获取选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆