Rename an item in a list

I want to rename the selected item in the list. How can i do this? Thank.

+3
source share
2 answers

Edit: repeat this quite a few years later; The following are the ways you can do this, depending on the user interface structure you are using. This assumes that you want to change the selected text.

ASP.Net WebForms

protected void ChangeListBoxSelectedItemText(string textToChangeTo)
{
    lstBoxExample.SelectedItem.Text = textToChangeTo;
}

WPF - Assuming ListBox Contains Label Objects

// To achieve this in WPF you have to cast the object
// This is because a ListBox can contain numerous types of UI objects
var selectedLabel = (Label)lstBoxExample.SelectedItem;
selectedLabel.Content = "Text to change to";

Winforms

// There may very well be a better way to do this
lstBoxExample.Items[lstBoxExample.SelectedIndex] = "New Item";
+4
source

ListBoxcontains objects. What exactly does “renaming” an element mean?

, , , ToString .

, , , ListBox, "" .

+2

Source: https://habr.com/ru/post/1781053/