Sum column values of list view

I have list view control which contains "Marks" Column. I want to count total of that column and display the result on a Label Control.. Any Help Regarding this will be appreciated.
Posted by Prince Mahajan 3/22/2014 11:35:12 PM
Total Answers : 2
Answer 1
User the below code :
 int sum = 0;

foreach (ListViewItem l in listView1.Items)
{
sum += Convert.ToInt32(l.SubItems[3].Text);
}
Label1.Text = sum.ToString();
Change the index of your column for which you want to count the sum..
Hope this will solve your problem..
Posted by StepCoder Team 3/24/2014 6:07:56 PM
Answer 2
You can use foreach loop for counting the sum of listview column.
int sum = 0;

foreach (ListViewItem l in listView1.Items)
{
sum += Convert.ToInt32(l.SubItems[3].Text);
}
Label1.Text = sum.ToString();
Posted by Andrew Dvorkin 3/26/2014 3:54:04 PM
Post your answer
Preview
Sign in to your account
Your Email : 
Password :   
Forgot your password
Don't have StepCoder account ?
Create a new account
 
Follow me on twitter
About Me
Harpreet Singh
I began programming with C++ when i was 17. Then at the middle of my study .NET came. Then I began to read C# and VB.NET. By the time i learnt SQL and ASP.NET, and developed some websites such as news portals that are active now. Currently i am running my own Software company.
Answer these questions! If you know the answer.