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
DxListBox<TData, TValue>.SelectionMode Property
Specifies selection mode.
Namespace : DevExpress.Blazor
Assembly :
DevExpress.Blazor.v24.2.dll
NuGet Package :
DevExpress.Blazor
# Declaration
# Property Value
Available values:
Name
Description
Single
Users can only select one List Box item at once.
Multiple
Users can select multiple items in List Box.
None
Users cannot select items in List Box.
# Single Selection
The default property value (ListBoxSelectionMode.Single ) specifies that users can select only one item at a time. To access/specify a selected item, use the Values property.
Run Demo: List Box - Overview
# Multiple Selection
Set the SelectionMode
property to ListBoxSelectionMode.Multiple to enable multiple selection in the List Box.
To select a range of rows, a user can click the first row in the range, hold down the Shift key, and click the last row in the range. To add a row to or remove a row from a selection, a user should hold down the Ctrl key and click that row. On touch devices, use long press gestures to select multiple rows.
If the ShowCheckboxes property is set to true
, users can click items or corresponding checkboxes to select items.
To access/specify selected items, use the Values property.
@using BlazorApp.Data
<DxListBox Data ="@ Staff.DataSource"
@bind-Values ="@ Values"
TextFieldName ="@ nameof(Person.Text)"
SelectionMode ="ListBoxSelectionMode.Multiple"
ShowCheckboxes ="true" >
</DxListBox >
@ code {
IEnumerable<Person> Values { get ; set ; } = Staff.DataSource.Take(1 );
}
namespace BlazorApp.Data {
public class Person {
public int Id { get ; set ; }
public string FirstName { get ; set ; }
public string LastName { get ; set ; }
public Department Department { get ; set ; }
public string Text => $"{FirstName} {LastName} ({Department} Dept.)" ;
}
public enum Department { Motors, Electronics, Software }
public override bool Equals (object obj ) {
if (obj is Person typedObj) {
return (this .Id == typedObj.Id) && (this .FirstName == typedObj.FirstName) && (this .LastName == typedObj.LastName)
&& (this .Department == typedObj.Department);
}
return base .Equals(obj);
}
}
using System ;
using System.Collections.Generic ;
namespace BlazorApp.Data {
public static class Staff {
private static readonly Lazy <List <Person >> dataSource = new Lazy<List<Person>>(() => {
var dataSource = new List<Person>() {
new Person() { Id= 0 , FirstName="John" , LastName="Heart" , Department=Department.Electronics },
new Person() { Id= 1 , FirstName="Samantha" , LastName="Bright" , Department=Department.Motors },
new Person() { Id= 2 , FirstName="Arthur" , LastName="Miller" , Department=Department.Software },
new Person() { Id= 3 , FirstName="Robert" , LastName="Reagan" , Department=Department.Electronics },
new Person() { Id= 4 , FirstName="Greta" , LastName="Sims" , Department=Department.Motors },
new Person() { Id= 5 , FirstName="Brett" , LastName="Wade" , Department=Department.Software },
new Person() { Id= 6 , FirstName="Sandra" , LastName="Johnson" , Department=Department.Electronics },
new Person() { Id= 7 , FirstName="Edward" , LastName="Holmes" , Department=Department.Motors },
new Person() { Id= 8 , FirstName="Barbara" , LastName="Banks" , Department=Department.Software },
new Person() { Id= 9 , FirstName="Kevin" , LastName="Carter" , Department=Department.Electronics },
new Person() { Id= 10 , FirstName="Cynthia" , LastName="Stanwick" , Department=Department.Motors },
new Person() { Id= 11 , FirstName="Sam" , LastName="Hill" , Department=Department.Electronics }};
return dataSource;
});
public static List<Person> DataSource { get { return dataSource.Value; } }
}
}
Run Demo: List Box - Multiple Selection
# Disable Selection
Set the SelectionMode
property to ListBoxSelectionMode.None to disable selection in the List Box.
@using BlazorApp.Data
<DxListBox Data ="@ Staff.DataSource"
@bind-Values ="@ Values"
TextFieldName ="@ nameof(Person.Text)"
SelectionMode ="ListBoxSelectionMode.None" >
</DxListBox >
@ code {
IEnumerable<Person> Values { get ; set ; } = Staff.DataSource.Take(1 );
}
namespace BlazorApp.Data {
public class Person {
public int Id { get ; set ; }
public string FirstName { get ; set ; }
public string LastName { get ; set ; }
public Department Department { get ; set ; }
public string Text => $"{FirstName} {LastName} ({Department} Dept.)" ;
}
public enum Department { Motors, Electronics, Software }
public override bool Equals (object obj ) {
if (obj is Person typedObj) {
return (this .Id == typedObj.Id) && (this .FirstName == typedObj.FirstName) && (this .LastName == typedObj.LastName)
&& (this .Department == typedObj.Department);
}
return base .Equals(obj);
}
}
using System ;
using System.Collections.Generic ;
namespace BlazorApp.Data {
public static class Staff {
private static readonly Lazy <List <Person >> dataSource = new Lazy<List<Person>>(() => {
var dataSource = new List<Person>() {
new Person() { Id= 0 , FirstName="John" , LastName="Heart" , Department=Department.Electronics },
new Person() { Id= 1 , FirstName="Samantha" , LastName="Bright" , Department=Department.Motors },
new Person() { Id= 2 , FirstName="Arthur" , LastName="Miller" , Department=Department.Software },
new Person() { Id= 3 , FirstName="Robert" , LastName="Reagan" , Department=Department.Electronics },
new Person() { Id= 4 , FirstName="Greta" , LastName="Sims" , Department=Department.Motors },
new Person() { Id= 5 , FirstName="Brett" , LastName="Wade" , Department=Department.Software },
new Person() { Id= 6 , FirstName="Sandra" , LastName="Johnson" , Department=Department.Electronics },
new Person() { Id= 7 , FirstName="Edward" , LastName="Holmes" , Department=Department.Motors },
new Person() { Id= 8 , FirstName="Barbara" , LastName="Banks" , Department=Department.Software },
new Person() { Id= 9 , FirstName="Kevin" , LastName="Carter" , Department=Department.Electronics },
new Person() { Id= 10 , FirstName="Cynthia" , LastName="Stanwick" , Department=Department.Motors },
new Person() { Id= 11 , FirstName="Sam" , LastName="Hill" , Department=Department.Electronics }};
return dataSource;
});
public static List<Person> DataSource { get { return dataSource.Value; } }
}
}
# Implements
DevExpress.Blazor.IListBox<TData, TValue>.SelectionMode
See Also