#961 – A ListBox Has Three Available Selection Modes

By default, a user can select one item at a time in a ListBox.

961-001

You can use the SelectionMode property of the ListBox to allow the user to select multiple items.  By default, the SelectionMode property has a value of SelectionMode.Single, allowing the user to select a single item.

You can set SelectionMode to Extended, allowing a user to select multiple items, as follows:

  • A mouse left-click selects a single new item, unselecting all previously selected items
  • Control + left-click selects/unselects an additional item.  Previously selected items remain selected.
  • Shift + left-click selects all items between the most recently selected item and the one being clicked (inclusive).  Previously selected items not in this range are unselected.
  • Control + Shift + left-click selects all items within a range without unselecting previously selected items

961-002

Setting SelectionMode to Multiple allows selecting multiple items by left-clicking:

  • Left-clicking an item selects or unselects the item
Advertisement

#364 – Allowing a User to Select Multiple Dates in a Calendar Control

By default, the Calendar control allows a user to select a single date.  You can set the SelectionMode property to allow the user to select more than one date.

SelectionMode (CalendarSelectionMode enumeration) can have one of the following values:

  • None – user can’t select date
  • SingleDate – select a single date  (default)

  • SingleRange – select a contiguous range of dates

  • MultipleRange – select multiple ranges of dates

If the SelectionMode is SingleDate, the SelectedDate property (DateTime) will contain the selected date.

If the SelectionMode is SingleRange or MultipleRange, the SelectedDates property (ObservableCollection of DateTime) will contain all of the selected dates.  The SelectedDate property will contain a copy of the first date in the SelectedDates collection.