Amazing User
Amazing User

Reputation: 3563

Changing value of the listBox

In WinForms how can I change value of the selected item in the listBox? My code doesn't works:

    private void button11_Click(object sender, EventArgs e)
    {
        listBox1.Text = "new value";
        listBox1.ValueMember = "new value";
        listBox1.SelectedValue = "new value";
        listBox1.SelectedItem = "new value";
        listBox1.Name = "new value";
    }

enter image description here

Edit1:

enter image description here

Upvotes: 0

Views: 6313

Answers (2)

Prince Unique
Prince Unique

Reputation: 31

Just :

listBox1.Items[listBox1.SelectedIndex] = "new Value";

Upvotes: 3

JC Borlagdan
JC Borlagdan

Reputation: 3618

try this:

listBox1.Items.Insert(listBox1.SelectedIndex, "new Value");
listBox1.Items.Remove(listBox1.SelectedItem);

Upvotes: 2

Related Questions