【问题标题】:Getting Selections of Multiselect ListView on VBA UserForm在 VBA 用户窗体上获取多选 ListView 的选择
【发布时间】:2018-09-13 21:40:48
【问题描述】:

listview sample我正在用户表单上使用列表视图。我启用了多选。我想在列表视图中选择多个项目,然后获取在同一表单上的其他一些文本框中找到的值,并将这些值推送到选定的项目子项(列)中。列表视图对我来说有点像新野兽。我的列表视图填充没有问题。我能够将数据推送到单个选定的行,但我不知道如何获取所有选定的行索引,然后相应地推送到所有子项。我最终只得到最后选择的行。

谢谢。

【问题讨论】:

标签: vba listview


【解决方案1】:

要获取选定的项目,请使用代码:

ListeCount = myListview.ListItems.Count
For i = 1 To ListeCount
        If myListview.ListItems.Item(i).Selected Then
        MsgBox myListview.ListItems.Item(i).Text
    End If
Next i

编辑#1:

ListeCount = myListview.ListItems.Count
For i = 1 To ListeCount
    If myListview.ListItems.Item(i).Checked Then
            MsgBox myListview.ListItems.Item(i).Text
            'Check if The column 2 of item 'i' is empty
            If myListview.ListItems.Item(i).SubItems(1) = vbNullString Then
                'Fill the empty column with a value
                myListview.ListItems.Item(i).SubItems(1) = "Test"
            End If
    End If
Next i

【讨论】:

  • MsgBox 返回为空 - 没有值
  • 检查您的列表视图是否充满数据?你是否用你的列表视图名称更改了“myListview”?
  • Listview 肯定被填满了,我更改了代码以匹配我的控件名称。
  • 第一列是一个复选框,这有关系吗?
  • 奇怪!你把代码放在哪里了?你把它放在命令按钮点击事件中了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 2020-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-24
  • 2015-01-17
相关资源
最近更新 更多