0
votes

Im struggling with some entity framework stuff.

I have this code :

 if (LsbSsd.SelectedIndex != -1)
        {
            Csharppcbuilder.Artikelen artikel = Database.pe.Artikelen.Where(x => x.Naam == LsbSsd.SelectedItem.ToString()).FirstOrDefault();
            databank.DeleteArtikel(artikel);


        }

My problem is that everything gets added to the other listbox and it does exactly what i want, but i cant seem to deselect items when i've added them to the other listbox.

What i've tried :

 if (LsbSsd.SelectedIndex != -1)
        {
            Csharppcbuilder.Artikelen artikel = Database.pe.Artikelen.Where(x => x.Naam == LsbSsd.SelectedItem.ToString()).FirstOrDefault();
            databank.DeleteArtikel(artikel);
            LsbSsd.SelectedIndex = -1;

        }

Hope someone can help me out.

edit : if someone needs more context i can provide it

1
Have you tried doing LsbSsd.SelectedItem = null; ?Mateusz
You would have to post code that duplicates the behavior. LsbSsd.SelectedIndex = -1; should work, and if it doesn't, something else is going on that we can't see. Check your other events.LarsTech

1 Answers

0
votes

To clear the ListBox's selection in WinForms if this LsbSsd.SelectedIndex = -1; is not working try using ClearSelected method LsbSsd.ClearSelected();