如何在VB.NET中的listView中汇总列的项目 [英] How to sumup items of a column in a listView in VB.NET

查看:415
本文介绍了如何在VB.NET中的listView中汇总列的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有........



任何人都可以帮助如何总结列表视图的特定列

并将其值传递给VB.NET中的文本框?



希望有人可以帮助我....

任何帮助都将是感谢...



请...帮助....:叹息:

hi to all........

Can anyone help on how to sumup a specific column of a listview
and pass its value to a textbox in VB.NET?

Hope someone can help me....
Any help will be appreciate...

pls...help.... :sigh:

推荐答案

更好的解决方案......更清洁的是:



The better solution...and cleaner one is:

Dim dblTotal as Double = 0
Dim dblTemp as Double

For Each lvItem As ListViewItem In ListView1.Items
   If Double.TryParse(lvItem.SubItems(2).Text, dblTemp) Then
       dblTotal += dblTemp
   End If
Next

TextBox1.Text = dblTotal





但你必须知道第一列也是一个subItem,所以上面的代码将总结第3列中的值。我还投入了TryParse方法,因为你需要检查并确保该列中实际存在双精度数。 (当然,如果它是数据绑定并且列是双列,那么你就不需要了。



But you have to know that the first column is also a subItem so the code above would sum up the values in column 3. I also threw in the TryParse method because you need to check and make sure that there are actually doubles in that column. (Of course if it's databound and the column is a Double column, then you wouldn't need that.


简单的方法是循环遍历所有行并获得总计。< br $> b $ b

然后将总数传递给文本框。



Simple way is to loop through all the rows and get a total that way.

Then pass the total to a text box.

Dim Li as ListViewItem
Dim dblTotal As Double

For Each Li In ListView1.Items
 If ListView1.Items.Count = 0 Then
  dblTotal = 0
  
  Else
dblTotal = dblTotal + CCur(Li.SubItems(4))

 End If
Next







我认为应该有效(显然可根据您的需求进行编辑!)



标记是否有用。




I think should work (obviously edit for your needs!)

Mark up if helpful.


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

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