Click here to Skip to main content
12,457,259 members (54,897 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB 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
 
good
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
  Permalink  
Comments
jleonorlane 17-May-10 3:35am
   
..how about in Listview
Rate this: bad
 
good
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]);
}
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 17 May 2010
Copyright © CodeProject, 1999-2016
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