Solved

ListView - Update A Single Item

Posted on 2002-06-08
3
327 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
[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
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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