Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unselect all items in a listbox after initial load

I have a ListBox that initially displays with the first item selected. I want it to display with no items selected. Is this possible?

like image 237
Jason Rae Avatar asked Aug 15 '11 21:08

Jason Rae


People also ask

How do I deselect a ListBox item?

If an item gets selected, it is added to the SelectedItems collection. So, if you want to deselect an item you call RemoveAt on the SelectedItems collection instead of the Items collection.

How do I reset my ListBox?

Clear ListBox With the DataSource = null Approach in C#DataSource property equal to null to remove the data source and then use the ListBox. Items. Clear() function to clear the previous items in the list box. The following code example shows us how we can empty a list box with the ListBox.

How do I select multiple items in ListBox?

Choose Multiple Items from ListboxOn the worksheet, click on a cell that has a drop down list. The VBA listbox pops up automatically, and shows all the choices from the cell's drop down list. Add a check mark to one or more of the items in the list box. When you're finished selecting items, click the OK button.

Can ListBox be edited?

To edit an item in a listbox, all you need is a simple editbox that overlays on a listbox item. The idea is to create a TextBox control and keep it hidden and show it whenever required. Two events are added to the EditBox. KeyPress event to check if the enter key is pressed when the user has finished editing the item.


2 Answers

ListBox.ClearSelected() 

or

ListBox.SelectedIndex = -1 

Of course, they are member methods.

like image 189
Vladimir Avatar answered Sep 22 '22 23:09

Vladimir


C# WPF (Clear Multiple)

Two more ways from code behind:

DemoListBox.SelectedItems.Clear(); DemoListBox.UnselectAll() 
like image 28
Robert Flynn Avatar answered Sep 18 '22 23:09

Robert Flynn