Solved

ListView - Update A Single Item

Posted on 2002-06-08
3
312 Views
Last Modified: 2012-08-25
I was wondering what is the best approach to updating single items in a listview.  I could clear all the items in the listview and then read them with the updated information, but that doesnt sound like the best approach when all I need to do is update a single cell for a
single item especially if the listview has 50+ items in it.

Any ideas?

Thanks
dl
0
Comment
Question by:larockd
3 Comments
 
LVL 22

Accepted Solution

by:
CJ_S earned 100 total points
ID: 7064596
If you know the index of that item AND you know the value you can just use

listview.Items[INDEX].Text = "New value";

If it comes from a database you might be able to do it with databinding.

CJ
0
 

Author Comment

by:larockd
ID: 7064993
Thank you that was exactly what I was looking for.

dl
0
 

Expert Comment

by:raheelasadkhan
ID: 38332853
You should also consider using the Tag property of WinForms controls. When populating the listview, each listitem has a Tag property. This allows you to associate the relevant object for that row.

So if you're populating a listview with a collection of people, you could use:

ListViewItem lvi = null;

foreach (Person p in persons)
{
    lvi = new ListViewItem();

    lvi.Tag = p;
    lvi.Text = p.FirstName;

    this.ListView.Items.Add(lvi);
}

Open in new window


So the next time you need to update a particular row, you can use the Person object to find it instead of remembering indexes. This makes it far more natural to access items programatically.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

13 Experts available now in Live!

Get 1:1 Help Now