vba在列表视图中选择值并在文本框中显示

时间:2015-12-08 12:33:42

标签: excel vba excel-vba

我想显示第3列而不是第1列的值。 Pleae建议改变是必要的。

Dim blnFoundFirstItem As Boolean
blnFoundFirstItem = False
Dim i As Integer
For i = 1 To ListView16.ListItems.Count
    If (ListView16.ListItems(i).Selected) Then
        If (Not blnFoundFirstItem) Then
            TextBox118.Text = ListView16.ListItems(i).Text
            blnFoundFirstItem = True
        Else
            TextBox118.Text = ListView16.ListItems(i).Text
        End If
    End If
Next i

1 个答案:

答案 0 :(得分:0)

使用ListSubItems()

Dim blnFoundFirstItem As Boolean
blnFoundFirstItem = False
Dim i As Integer
For i = 1 To ListView16.ListItems.Count
    If (ListView16.ListItems(i).Selected) Then
        If (Not blnFoundFirstItem) Then
            TextBox118.Text = ListView16.ListItems(i).ListSubItems(3).Text
            blnFoundFirstItem = True
        Else
            TextBox118.Text = ListView16.ListItems(i).ListSubItems(3).Text
        End If
    End If
Next i