Solved

loop through listview items c#

Posted on 2009-04-09
4
2,863 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
[X]
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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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