Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ListView - Update A Single Item

Posted on 2002-06-08
3
Medium Priority
?
343 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 400 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

926 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