Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

loop through listview items c#

Posted on 2009-04-09
4
2,859 Views
Last Modified: 2012-05-06
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
Comment
Question by:Pit76
4 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24107356
can u post the code how u fill the list view
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24107359
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 24107386
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
 

Author Closing Comment

by:Pit76
ID: 31568538
Thx! That works like a charm :d
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question