Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a list view control. which have third column of int values... i want to sum all the values of that column on click of the button..
Posted
Comments
bbirajdar 4-Jan-13 8:46am    
okay...So what exact help do you expect from us?

What about a loop?
C#
int sum = 0;
foreach (ListViewItem li in lvw)
  sum += int.Parse(li.Subitems[2].Text);
 
Share this answer
 
Comments
Espen Harlinn 7-Jan-13 4:15am    
Something like that would do the trick :-D
Hi
If you want show sum of all columns you need 2 loops.
I think bellow code can be helpful for you:


int totalSum= 0;
foreach (ListViewItem item in [YourListView])
	for(int i = 0; i < [NumberOfColumns]; i++)
		totalSum += int.Parse(item.Subitems[i].Text);
 
Share this answer
 
Hi,

Try like this:

C#
decimal gtotal = 0;
        foreach (ListViewItem lstItem in orderlist.Items)
        {
            gtotal += decimal.Parse(lstItem.SubItems[3].Text);
        }
        grandtotal.Text = Convert.ToString(gtotal);


Thanks
 
Share this answer
 

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