Solved

loop through listview items c#

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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