本文介绍了如何在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....

推荐答案

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


// 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中的所有项目(双精度或整数)求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 22:32