Hello. How to replace an item in a listBox with the one entered in the text field and update the listBox?

ICollectionView myDataView = CollectionViewSource.GetDefaultView(listBox1.Items); using (myDataView.DeferRefresh()) { myDataView.Refresh(); } 

I'm trying to update the view, but I get an error.

    1 answer 1

    This piece of code replaces the value in the ListBox with the one entered from the text box. Updates everything:

      int i = listBox1.SelectedIndex; listBox1.Items.RemoveAt(i); listBox1.Items.Insert(i, textBox1.Text); 
    • one
      listBox1.Items[i] = textBox1.Text; Doesn't it help? - Specter
    • Removes the first item in the listBoxe and gets an empty value. int i = listBox1.SelectedIndex; listBox1.Items.RemoveAt (i); listBox1.Items.Insert (i, textBox1.Text); - Demon
    • listBox1.Items [i] = textBox1.Text; And this code does the same thing. - Demon
    • Removes the first element makes it empty and the new element inserts 2 - Demon