简体   繁体   中英

Unselect selected listbox item after hitting a button?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM