ListBoxEdit.SelectionMode Property
Gets or sets the selection mode for the ListBoxEdit
control. This is a dependency property.
Namespace: DevExpress.Xpf.Editors
Assembly: DevExpress.Xpf.Core.v25.1.dll
NuGet Package: DevExpress.Wpf.Core
Declaration
Property Value
Type | Description |
---|---|
SelectionMode | A SelectionMode enumeration value that specifies the editor’s selection behavior. |
Remarks
The SelectionMode
property specifies how users can select items within the ListBoxEdit
control.
The ListBoxEdit
supports the following selection modes:
- Single (default)
- Users can select only one item at a time.
- Multiple
- Users can select multiple items by clicking with the mouse or pressing the Space bar.
- Extended
- Users can select multiple consecutive items by holding the Shift key while clicking. Holding Ctrl and clicking toggles an item’s selection state.
Each time the selection changes, the ListBoxEdit.SelectedIndexChanged event is fired.
Tip
The ListBoxEdit.EditValue
property returns a List<T><Object,> containing selected items when multiple items are selected. This list is recreated each time the selection changes. Modifying this list does not change the actual selection.
Use the ListBoxEdit.SelectedItems property to programmatically manage selected items.
Note
If the
ListBoxEdit
is configured as a checked list, theSelectionMode
property is automatically set toMultiple
and cannot be changed.If the
ListBoxEdit
is configured as a radio list, theSelectionMode
property is automatically set toSingle
and cannot be changed.
Example
The following code example creates a ListBoxEdit
control with multiple item selection enabled:
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:local="clr-namespace:ListBoxEdit"
x:Class="ListBoxEdit.MainWindow"
Title="MainWindow" Height="800" Width="1000">
<Window.DataContext>
<local:MainViewModel />
</Window.DataContext>
<Grid>
<dxe:ListBoxEdit x:Name="listBoxEdit" HorizontalAlignment="Left" Margin="284,331,0,0" VerticalAlignment="Top" Height="213" Width="138"
SelectionMode="Multiple"
ItemsSource="{Binding Items}"
EditValue="{Binding SelectedItems, Mode=TwoWay}"
DisplayMember="Name"/>
</Grid>
</dx:ThemedWindow>
using DevExpress.Xpf.Core;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
namespace ListBoxEdit {
public partial class MainWindow : ThemedWindow {
public MainWindow() {
InitializeComponent();
}
}
public class MainViewModel : INotifyPropertyChanged {
public ObservableCollection<Item> Items { get; set; }
public List<Object> SelectedItems { get; set; }
public MainViewModel() {
Items = new ObservableCollection<Item>(Enumerable.Range(0, 10)
.Select(c => new Item {
Id = c,
Name = "Item " + c }));
SelectedItems = new List<Object>(){
Items[0],
Items[2]
};
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class Item {
public int Id { get; set; }
public string Name { get; set; }
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SelectionMode property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.