From d1b40eb1ac7b50053edb15ff7c177d272035b24f Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 21 Aug 2026 15:06:22 +0300 Subject: [PATCH 1/2] kb(ListBox): Enhance checkbox selection article --- knowledge-base/listbox-checkbox-selection.md | 55 +++++++++++++++++--- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/knowledge-base/listbox-checkbox-selection.md b/knowledge-base/listbox-checkbox-selection.md index ba4bed790..3f6a6736f 100644 --- a/knowledge-base/listbox-checkbox-selection.md +++ b/knowledge-base/listbox-checkbox-selection.md @@ -6,7 +6,7 @@ page_title: How to Select ListBox Items with CheckBoxes slug: listbox-kb-checkbox-selection position: tags: telerik, blazor, listbox, selection, checkbox -ticketid: +ticketid: 1718138 res_type: kb components: ["listbox"] --- @@ -37,6 +37,7 @@ This KB article answers the following questions: 1. The CheckBox `Value` must be `true` if the current item (`ItemTemplate` `context`) is a member of the ListBox `SelectedItems` collection. 1. The CheckBox `ValueChanged` handler must add or remove the current ListBox item from the `SelectedItems` collection. 1. Wrap the CheckBox component in a ``, so that the checkbox clicks do not interfere with the built-in ListBox selection feature. +1. (optional) Use the [ListBox `SelectedItemsChanged` event](slug:listbox-events#selecteditemschanged) to toggle item selection without the need to hold the `Ctrl` key. 1. (optional) Apply some padding on the `` element, so that if the user clicks near the checkbox, but outside it, the ListBox `SelectedItems` collection doesn't reset to a single item. >caption Using checkboxes for ListBox selection @@ -45,17 +46,29 @@ This KB article answers the following questions: ListBox SelectionMode: + @bind-Value="@RadioGroupValue" + Layout="@RadioGroupLayout.Horizontal" + OnChange="@((object currentValue) => ListBoxSelectedItems = new List())" />
+ + +
+
+ @@ -66,9 +79,9 @@ ListBox SelectionMode: + ValueChanged="@( (bool newValue) => OnItemCheckBoxValueChanged(newValue, context) )" /> - @context.Name + @context.Name @@ -91,8 +104,34 @@ ListBox SelectionMode: }; private ListBoxSelectionMode RadioGroupValue { get; set; } = ListBoxSelectionMode.Multiple; + private bool ShouldSelectWithoutCtrl { get; set; } = true; + + private void ListBoxSelectedItemsChanged(IEnumerable newSelectedItems) + { + if (RadioGroupValue == ListBoxSelectionMode.Single || !ShouldSelectWithoutCtrl) + { + ListBoxSelectedItems = newSelectedItems; + return; + } + + if (newSelectedItems.Count() == 1 && ListBoxSelectedItems.Count() > 0) + { + if (!ListBoxSelectedItems.Contains(newSelectedItems.First())) + { + ((List)ListBoxSelectedItems).AddRange(newSelectedItems); + } + else + { + ((List)ListBoxSelectedItems).RemoveAll(x => newSelectedItems.Contains(x)); + } + } + else + { + ListBoxSelectedItems = newSelectedItems; + } + } - private void OnCheckBoxValueChanged(bool newValue, ListBoxModel item) + private void OnItemCheckBoxValueChanged(bool newValue, ListBoxModel item) { var currentSelection = new List(ListBoxSelectedItems); From f5080b9f2a06c89658250ee64decd957aab7476f Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 21 Aug 2026 15:08:16 +0300 Subject: [PATCH 2/2] Apply suggestion --- knowledge-base/listbox-checkbox-selection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knowledge-base/listbox-checkbox-selection.md b/knowledge-base/listbox-checkbox-selection.md index 3f6a6736f..558d78858 100644 --- a/knowledge-base/listbox-checkbox-selection.md +++ b/knowledge-base/listbox-checkbox-selection.md @@ -81,7 +81,7 @@ ListBox SelectionMode:
- @context.Name + @context.Name