We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to clear selection in a button click using MVVM in SfDataGrid?

Platform: Xamarin.Forms |
Control: SfDataGrid
Tags: selection, mvvm

SfDataGrid allows you clear the selection programmatically in two ways either by changing the SelectionMode to “None” or by using the SelectionController.ClearSelection method. You can clear the selection in a button click in MVVM by adding command and command parameter to the button.

Refer the below code example in which a Command is triggered for clearing the selection in SfDataGrid. The reference of SfDataGrid is passed as a CommandParameter to a button in order to clear the selection in the view model.







Sample Link:

How to clear selection in a button click using MVVM in SfDataGrid?

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment
Jul 31, 2020

dataGrid.SelectionController.ClearSelection(); is not working in latest release.

Sivaraman Sivagurunathan [Syncfusion]
Aug 03, 2020

Hi Ganesh,

We have provide the Cell Selection in last main release. For that, we have change the SelectionController Property’s type is changed from SelectionController to SelectionControllerBase So that you cannot access the ClearSelection() method. We have mentioned that in release notes. You can access the clear selection method, with cast the SelectionController as GridSelectionController or you can call the DataGrid.ClearSelection() method. We have attached the sample for your reference you can download the same from the below.

private void ClearSelectionCommand(object obj) { var dataGrid = obj as SfDataGrid;

//Approach – 1:
//Clear selection using selection mode
dataGrid.SelectionMode = SelectionMode.None;

//Approach – 2:
//Clear selection using selection controller
(dataGrid.SelectionController as GridSelectionController).ClearSelection();

//Approach – 3:


Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGridSample_(20)60879620

Breaking changes: https://help.syncfusion.com/xamarin/release-notes/v18.2.0.44?type=all#sfdatagrid-breaking-changes

Regards, Sivaraman S

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile