请帮我查看Listview选中的项目 [英] Please Help me on Listview checked items

查看:50
本文介绍了请帮我查看Listview选中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人帮我循环一下如何在vb.net的列表视图中获取所有选中的项目

我按下按钮时就称这个循环
但是问题是我在With列表视图的开头到End With的开头有一个错误

Please someone help me on doing a loop on how to get all the checked items in listview in vb.net

I''m calling this loop when i press a button
but the problem is that i have an error in the beginning of the With listview to End With

Dim i As Integer = 0
Dim rCnt As Integer = ListView1.Columns.Count
For i = 0 To rCnt - 1
    With ListView1
        SaveItem(.Items(1, i).Value, .Items(2, i).Value)
    End With
Next



这是我的SaveItem()函数



And here''s my SaveItem() Function

Public Sub SaveItem(ByVal strBrchID As String, _
                     ByVal strBrchName As String)
.........
End Sub



[修改:在格式代码中添加了前置标记]



[Modified: added pre tags to format code]

推荐答案

似乎您不了解ListView.

您的问题是ListView.Items没有两个参数. ListViewItem也没有Value属性.看起来您正在混合使用VB6和VB.NET.

首先,您说的问题标题是您需要获取CheckedItems的帮助.但是您的代码根本不处理这些.然后,我已经说过您的代码存在的问题.

如果只想处理CheckedItems,则ListView具有CheckedItems集合.

您可以简单地执行以下操作:
It looks like you don''t understand the ListView.

Your problem is that ListView.Items does not take two parameters. Nor does a ListViewItem have a Value property. It looks like you''re mixing VB6 and VB.NET.

To begin with, you said your question title said you needed help with getting CheckedItems. But your code doesn''t deal with that at all. Then, there''s the problems with your code that I''ve already said.

If you want to deal with CheckedItems only, the ListView has a CheckedItems collection.

You can simply do:
For Each item As ListViewItem In ListView1.CheckedItems

Next



然后,要访问不同的列,您要访问每个项目的SubItems.但是请记住,第一列是SubItem(0).如果要显示什么,就想要



Then, to access different columns, you want to access the SubItems of each item. But remember that the first column is SubItem(0). If you want what is displayed, you want

item.SubItem(0).Text


还有一些其他对ListViewItem设置非常有用的属性,例如Tag属性,它可以是任何Object或Name属性.

不过,首先,实际上是下次查看ListView类和ListViewItem类,以了解如何使用它们.


There are other properties that can be very useful to set with a ListViewItem such as the Tag property which can be any Object or the Name property.

First, though, actually look at the ListView class next time and the ListViewItem class to see how to use them.


这篇关于请帮我查看Listview选中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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