Solved

loop through listview items c#

Posted on 2009-04-09
4
2,856 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

Suggested Solutions

Title # Comments Views Activity
Install Problem 13 32
Javascript to set controls visibility 5 37
SqlDependency to get update from sql to my c# app 2 41
JSON  parse help 7 26
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 …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

809 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