Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.v24.2.dll

NuGet Package: DevExpress.Wpf.Core

#Declaration

public SelectionMode SelectionMode { get; set; }

#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.

Multiple Item Selection Mode - WPF ListBoxEdit, DevExpress

Run Demo: ListBoxEdit

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, the SelectionMode property is automatically set to Multiple and cannot be changed.

  • If the ListBoxEdit is configured as a radio list, the SelectionMode property is automatically set to Single and cannot be changed.

#Example

The following code example creates a ListBoxEdit control with multiple item selection enabled:

xml
<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>
C#
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; }
    }
}

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.

See Also