Click here to Skip to main content
11,796,275 members (76,633 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
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 16-May-10 19:40pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
jleonorlane at 17-May-10 3:35am about in Listview
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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]);
jleonorlane at 17-May-10 3:35am
how about in VB.NET
Sandeep Mewara at 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)

  Print Answers RSS
0 Maciej Los 570
1 Abhinav S 392
2 OriginalGriff 340
3 CPallini 269
4 KrunalRohit 249
0 OriginalGriff 2,012
1 Maciej Los 1,615
2 KrunalRohit 1,310
3 CPallini 1,015
4 Richard MacCutchan 828

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 17 May 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100