Hashey100
Hashey100

Reputation: 984

Unloading image from picturebox if string matches

I have two listbox that allows the user to transfer items from the 1st list box into the 2nd listbox

when the user clicks on a button it compares the selected item and if it matches a specific string if it does then it loads up images into a pictureboxes.

I made a function that removes current items added to the second listbox , but i want to somehow read which item was selected and removed. I thought i could put something like

if(listBox2.Items.RemoveAt(listBox2.SelectedIndex="String") { picturebox.Image=null; }

example code

   private void button2_Click(object sender, EventArgs e)
    {
        listBox2.Items.RemoveAt(listBox2.SelectedIndex); 
    }

Upvotes: 2

Views: 1714

Answers (1)

Steve
Steve

Reputation: 216313

It's not clear what are you trying to do.
However if you want to remove an image from a picturebox based on the Item selected in a listbox, perhaps this could help:

private void button2_Click(object sender, EventArgs e)     
{    
     if(listbox2.SelectedIndex >= 0)
     {
         string curItem = listBox2.Items[listbox2.SelectedIndex].ToString();
         if(curItem == "SomeOtherString")
         {
             listBox2.Items.RemoveAt(listBox2.SelectedIndex);      
             picturebox.Image.Dispose();
             picturebox.Image = null; // Not really necessary
         }
     }
} 

Upvotes: 1

Related Questions