如何在Listview中计数项目 [英] how to item Count in Listview
本文介绍了如何在Listview中计数项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Listview
SrNo ItemName
1 a1
2 a2
3 a3
4 a4
5 a1
6 a2
7 a1
8 a3
9 a1
10 a1
怎么办
商品名称| TotalCount
A1 | 5
a2 | 2
a3 | 2
a4 | 1
in vb.net
I have An Listview
SrNo ItemName
1 a1
2 a2
3 a3
4 a4
5 a1
6 a2
7 a1
8 a3
9 a1
10 a1
how to get
Item Name| TotalCount
A1 | 5
a2 | 2
a3 | 2
a4 | 1
in vb.net
推荐答案
您可以使用字典<字符串,整数>
用于此目的。String
表示项目的位置,Integer
表示项目在中出现的次数的ListView
。在一次迭代中,您可以填充字典
:如果该项已经存在,您只需递增Integer
值,另一方面,如果该项目尚不存在于字典
中,则添加它并设置整数
到0
。
You may use aDictionary<String,Integer>
for the purpose. Where theString
represents the item and theInteger
represent how many times the item occurred in theListView
. In a single iteration you can populate theDictionary
: if the item is already present you just increment theInteger
value, on the other hand, if the item doesn't yet exist in theDictionary
, then you add it and set theInteger
to0
.
使用此代码..
use this code..
dim l as integer
l = listview1.Items.Count
msgbox(l)
这篇关于如何在Listview中计数项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文