ListView1.SelectedIndices怎样用
时间: 2024-05-10 07:16:41 浏览: 21
ListView1.SelectedIndices 属性用于获取 ListView 控件中所有选定项的索引。可以按照以下步骤使用 SelectedIndices 属性:
1. 在窗体上添加 ListView 控件,并添加一些项。
2. 在代码中使用 SelectedIndices 属性来获取选定项的索引。
例如,下面的代码演示如何获取 ListView1 控件中所有选定项的索引:
```vb
For Each index As Integer In ListView1.SelectedIndices
MsgBox(index)
Next
```
该代码将弹出包含所有选定项索引的消息框。如果没有选定项,则 SelectedIndices 属性将返回一个空的整数集合。
注意:SelectedIndices 属性是只读的,不能直接设置它的值。如果要选择或取消选择项,请使用 ListViewItem.Selected 属性。
相关问题
ListView1.SubItems.AddRange的AddRange如何使用
`ListView1.SubItems` 是 `ListViewItem` 的一个属性,它是一个包含子项的集合。`AddRange` 方法可以向这个集合中添加多个 `ListViewSubItem` 对象。
以下是使用 `AddRange` 方法向 `ListView1.SubItems` 添加三个子项的示例代码:
```
Dim subItems As New List(Of ListViewItem.ListViewSubItem)
subItems.Add(New ListViewItem.ListViewSubItem(Nothing, "SubItem 1"))
subItems.Add(New ListViewItem.ListViewSubItem(Nothing, "SubItem 2"))
subItems.Add(New ListViewItem.ListViewSubItem(Nothing, "SubItem 3"))
Dim item As New ListViewItem("Item 1")
item.SubItems.AddRange(subItems.ToArray())
ListView1.Items.Add(item)
```
在这个示例中,我们首先创建了一个 `List(Of ListViewItem.ListViewSubItem)` 对象 `subItems`,并向其中添加了三个 `ListViewSubItem` 对象。然后我们创建了一个 `ListViewItem` 对象 `item`,并使用 `AddRange` 方法向其子项集合 `SubItems` 添加 `subItems` 中的三个子项。最后,我们将 `item` 添加到 `ListView1` 控件的项集合中。
If ListView2.Items(i).Text = ListView1.SelectedItems(0).Text
如果ListView2.Items(i).Text等于ListView1.SelectedItems(0).Text,那么ListView2.Items(i).Text和ListView1.SelectedItems(0).Text的值是相同的。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)