如何在VB.NET中对Listview中的所有项目(双精度或整数)求和 [英] How to Sum all items(Double or Integer) in Listview in VB.NET

查看:76
本文介绍了如何在VB.NET中对Listview中的所有项目(双精度或整数)求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我解决有关如何对列表视图中特定列的所有项求和的问题,该列的数据类型为"DOUBLE或INTEGER"

请帮我....

任何帮助将不胜感激....

Can anyone help me regarding on how to sum all items in a specific column in listview which is the data type of the column is "DOUBLE or INTEGER"

Please help me ....

Any Help will be appreciated....

推荐答案

类似
的东西
Something like

For Each col As DataGridViewColumn In dgvMyDataGrid.Columns
    If col.ValueType Is GetType(Integer) OrElse col.ValueType Is GetType(Double) Then
        Dim sum As Double = 0
        For Each row As DataGridViewRow In dgvMyDataGrids.Rows
            'If the column is visible:
            If row.Cells(col.DisplayIndex).Value IsNot Nothing AndAlso Not IsDBNull(row.Cells(col.DisplayIndex).Value) Then
                sum += Convert.ToDouble(row.Cells(col.DisplayIndex).Value)
            End If
        Next row
    End If
Next col


在listitems上循环,获取您正在谈论的每个列表项的值并对它们进行任何数学排列.

类似的东西:
Go for a loop on listitems, get the value of each list item that you are talking of and do any mathematical permutation you want to on them.

something like:
// This is in C#
double someValue = 0;
foreach(ListItem li in myList.Items)
{
  // play with someValue
  // you need to put validation checks to make sure the value you 
  // are converting is of correct datatype.
  // This is just a sample code
  someValue += Convert.ToDouble(li[2]);
}


这篇关于如何在VB.NET中对Listview中的所有项目(双精度或整数)求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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