I want to create a if statement that recognizes which string has been removed from a specific list box. I thought i could do an if statement similar to the one below and get it to work but it tells me it has invalid arguements – if anyone can guide me it would appreciated
private void button2_Click(object sender, EventArgs e)
{
listBox2.Items.RemoveAt(listBox2.SelectedIndex);
if(listBox2.Items.RemoveAt(listBox2.SelectedItems.ToString().Equals("Test")))
{
picturebox.Image = null;
}
}
You need to check the
SelectedItembefore removing it:I’ve also added a check to ensure that an item is actually selected (since you would get errors otherwise).