如何在Listview中计数项目 [英] how to item Count in Listview

查看:64
本文介绍了如何在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 a Dictionary<String,Integer> for the purpose. Where the String represents the item and the Integer represent how many times the item occurred in the ListView. In a single iteration you can populate the Dictionary: if the item is already present you just increment the Integer value, on the other hand, if the item doesn't yet exist in the Dictionary, then you add it and set the Integer to 0.


使用此代码..



use this code..

dim l as integer
l =  listview1.Items.Count
msgbox(l)


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

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