This is a migrated thread and some comments may be shown as answers.

Programmatic Select All Feature

1 Answer 165 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Edward
Top achievements
Rank 1
Edward asked on 27 Jul 2012, 06:06 PM
On the RadListBox Control, can all items be programmatically selected in xaml or code-behind. And also, can all items be unselected programmatically in xaml or code-behind?

1 Answer, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 30 Jul 2012, 01:58 PM
Hi Edward,

In order to select all of the ListBox control items you should use the SelectAllCommand command in the Loaded event of the control. the next code snippet represents the described approach:

In XAML:
<telerik:RadListBox SelectionMode="Multiple" Loaded="RadListBox_Loaded" />


In the code behind:
private void RadListBox_Loaded(object sender, RoutedEventArgs e)
{
    RadListBox.SelectAllCommand.Execute(null, sender as RadListBox);
}

If you want to select all the items of RadListBox without using the code behind you should make an attached property and attach it to the control.

On your second question, to deselect all items you can use the SelectedItems.Clear() method. Here is a sample code snippet showing that:
this.theListBox.SelectedItems.Clear();

Hope this is helpful.

Greetings,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ListBox
Asked by
Edward
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Share this question
or