larockd
asked on
ListView - Update A Single Item
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
single item especially if the listview has 50+ items in it.
Any ideas?
Thanks
dl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:
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.
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);
}
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.
ASKER
dl