Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2885
  • Last Modified:

loop through listview items c#

Hi all,

I have a listviewcontrol (details with 3 columns)  on my form wich I  fill row by row with a button. This works fine but now I want to loop through it and say get each value of the third column..
How do I do that? how do I get the value for each row of the third column? I need to show the sum of this column in a textbox..

Grts
0
Pit76
Asked:
Pit76
1 Solution
 
Gautham JanardhanCommented:
can u post the code how u fill the list view
0
 
RiteshShahCommented:
0
 
Wayne Taylor (webtubbs)Commented:
Try this....

    private void SumItems()
    {
        double sum = 0;
        foreach (ListViewItem lvi in ListView1.Items) {
            sum += Convert.ToDouble(lvi.SubItems(2).Text);
        }
        TextBox1.Text = "Sum = " + sum;
    }

Open in new window

0
 
Pit76Author Commented:
Thx! That works like a charm :d
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now