Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure ListBox in WPF so that I will be possible to select multiple items without holding CTRL key

I have a Listbox that allows user to select multiple items. Normally user can do that by holding CTRL key and clicking the item he or she wants to select.

Is it possible to configure this listbox so that the user will not have to hold the CTRL key when selecting items ? So that he or she will just click the item (without holding anything) and the item will be selected(diselected if it was selected previously) ?

Thank you

like image 221
Rasto Avatar asked Jun 06 '10 11:06

Rasto


People also ask

How do I add data to a ListBox in WPF?

On button click event handler, we add the content of TextBox to the ListBox by using the ListBox. Items. Add method. Now if you enter text in the TextBox and click Add Item button, it will add contents of the TextBox to the ListBox.

What is ListBox WPF?

ListBox is a control that provides a list of items to the user item selection. A user can select one or more items from the predefined list of items at a time. In a ListBox, multiple options are always visible to the user without any user interaction.


1 Answers

Use

SelectionMode="Multiple"

From the MSDN:

The SelectionMode property determines how many items a user can select at one time. You can set the property to Single (the default), Multiple, or Extended. The following table described the behavior of these enumeration values.

Single The user can select only one item at a time.

Multiple The user can select multiple items without holding down a modifier key.

Extended The user can select multiple consecutive items while holding down the SHIFT key or non-consecutive items by holding down the CTRL key and clicking the items.

like image 185
ChrisF Avatar answered Sep 20 '22 16:09

ChrisF