Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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....
Posted

Something like

VB
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
 
Share this answer
 
Comments
jleonorlane 17-May-10 3:35am    
..how about in Listview
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:
C#
// 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]);
}
 
Share this answer
 
Comments
jleonorlane 17-May-10 3:35am    
how about in VB.NET
Sandeep Mewara 17-May-10 3:41am    
This was to give you an idea... try out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900