5 Answers, 1 is accepted
There are a couple of ways to go:
1. You can call UnselectAll() method of RadGridView.
2. You can clear the SelectedItem property;
3. You can clear the SelectedItems collection.
When do you want to clear the selection ? What is the exact scenario that you want to achieve ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Would you clarify a bit how do you expect this item to be deselected - do you want to click on it, to click on another item and clear all selected items, click outside the grid ? What is the exact scenario that you want to achieve ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
1. I only want one row to be selected at a time. Any other rows to be deselected when a row is selected.
2. I want to be able to un-select that row by clicking on the row so that no rows at all are selected.
You can try to set CanUserSelect property of RadGridView to "False" and handle PreviewMouseKeyDown event like follows:
public MainWindow()
{
InitializeComponent();
this.clubsGrid.IsReadOnly = true;
this.AddHandler(RadGridView.PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(OnPreviewMouseDown), true);
}
private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
FrameworkElement clickedElement = e.OriginalSource as FrameworkElement;
GridViewRow clickedRow = clickedElement.ParentOfType<
GridViewRow
>();
if (clickedRow != null)
{
clickedRow.IsSelected = !clickedRow.IsSelected;
}
}
On the other hand, each item can be unselected by clicking on it while holding Cntr key.
Let me know whether the suggested approach meets your requirements.
All the best,
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>