Solved

ListView - Update A Single Item

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

22 Experts available now in Live!

Get 1:1 Help Now