I
I
Ilya Chirkov2014-11-26 18:54:48
.NET
Ilya Chirkov, 2014-11-26 18:54:48

How to change the name of the selected item in a ListBox?

Let's say there is a ListBox with elements "Value1", "Value2"
How to rename one of them during program execution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
cjey, 2014-11-26
@cjey

private void button1_Click(object sender, EventArgs e)
{
    listBox1.Items[0] = ((String)listBox1.Items[0]).Replace('e','!') + "_Clicked";
}

O
Oxoron, 2014-11-27
@Oxoron

// listbox lb - Your ListBox
// string newValue - New value
here lb.Items[lb.SelectedIndex] = newValue; // This code replaces the selected element with a new value. Instead of lb.SelectedIndex, you can specify the index of any other element. If there are no selected elements, you can catch an exception.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question