Unselect all items in a listbox after initial load
69,539
Solution 1
ListBox.ClearSelected()
or
ListBox.SelectedIndex = -1
Of course, they are member methods.
Solution 2
C# WPF (Clear Multiple)
Two more ways from code behind:
DemoListBox.SelectedItems.Clear();
DemoListBox.UnselectAll()
Solution 3
This should do it:
lb_MyListBox.SelectedIndex = -1;
Solution 4
For clear multiple ListBox
foreach (Control ctrl in ctrls)
{
((ListBox)ctrl).SelectedIndex = -1;
ClearInputs(ctrl.Controls);
}
Calling Method on button and from where you want to execute
ClearInputs(Page.Controls);
Author by
Jason Rae
Updated on July 22, 2022Comments
-
Jason Rae almost 2 years
I have a ListBox that initially displays with the first item selected. I want it to display with no items selected. Is this possible?
-
kakridge almost 13 yearsSelectedIndex = -1 will not work if you have a multi-edit listbox.
-
bonCodigo almost 10 years@Vladimir Does it work for a multi-value extended listbox as well? In my case this code doesn't work.
-
bonCodigo almost 10 years@kakridge precisely. I am facing the issue for mult-selct extend. What's the workaround?
-
Peet over 5 yearsThe first one worked a treat for my CheckedListBox. Thanks!
-
Leo about 4 yearsListBox.ClearSelection();