0
votes

im trying delete an item on a listbox but when I press the button to delete it the first line of the code in the private void listBox1_SelectedIndexChanged(object sender, EventArgs e) gets an error.

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  {
      textBox1.Text = listBox1.SelectedItem.ToString();   
  }

here is the error Object reference not set to an instance of an object.

1
Put a breakpoint on it and figure out precisely what's null in that line. Is it the ListBox? Is it the SelectedItem?tmesser
I think that after you delete the item the selected index of the drop down list get's changed to the item you've just deletedMihai
I think is is the selecteditemOrange Light
how would i make a breakpoints for it?Orange Light
@OrangeLight in visual studio just click on the margin to the left of the line number, that will create a breakpoint. More info here. Also, just FYI, if you don't preface your comment with @YYY, I don't see that you've replied.tmesser

1 Answers

0
votes

Either textBox1, listBox1, or listBox1.SelectedItem is null.

When the exception comes up, use the locals and watch tab at the bottom of your screen to see which one it is.