pradeepradyumna
pradeepradyumna

Reputation: 1072

C# Is it possible to change e.Label value in ListView

I have ListView where I'm trying to edit a row. But also I need to update the e.Label in AfterLabelEdit. Is there any workaround where I can change the value of e.Label in this event. For example, if I have typed 'Zip' and when I hit enter it should become 'Zip1'

Upvotes: 2

Views: 344

Answers (2)

Reza Aghaei
Reza Aghaei

Reputation: 125197

You can cancel the edit based on some criteria and assign a new value to text of the item.

The Label contains proposed value for the label, so you can write the criteria based on that. Then to cancel the edit, it's enough to set CancelEdit property of the event argument to true. Then using its Item property yo ucan find the editing item and set the new label for it.

For example:

private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
    if (e.Label == "something")
    {
        e.CancelEdit = true;
        ((ListView)sender).Items[e.Item].Text = "something else";
    }
}

Upvotes: 1

ariaman5
ariaman5

Reputation: 132

If you edit the value of a row in a listview , like "zip" , to "zip1" , the value of e.label in AfterLabelEdit event will be changed automatically after you hit Enter or listview leaves focus.You can not assign a value to e.label like e.label="zip1"; and the value of e.label won't be anything except "zip1" which is the value after edition.

Upvotes: 1

Related Questions