Jack
Jack

Reputation: 16724

Can I update value in a ListView?

I'm adding values to a ListView using this:

ListViewItem item1 = new ListViewItem("s1");
item1.SubItems.Add("s2");

ListViewItem item2 = new ListViewItem("s3");
item2.SubItems.Add("s4");

ListViewItem item3 = new ListViewItem("s5");
item3.SubItems.Add("s6");

listView1.Items.AddRange(new ListViewItem[] { item1, item2, item3 });

Now I want to change say, s2 to s2_baa. I'm finding a bit difficult to use ListView... is it possible? if so, how can I do this?

Upvotes: 1

Views: 56

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222700

You can change the Text Property of SubItem

ListViewItem lvi = listView1.FindItemWithText("s2");
if (lvi != null)
{
    lvi.SubItems[0].Text = "s2_baa";
}

Upvotes: 1

Related Questions