Solved

loop through listview items c#

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now