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

How do I de-select a row after it's selected?

I'm currently using a SFDataGrid in WPF and I was wondering how do I de-select a row after it's selected?

Is there a row selected event so I can do like a 'if old selected row == new row selected then row selected = null? 

7 Replies

FP Farjana Parveen Ayubb Syncfusion Team August 27, 2019 11:22 AM UTC

Hi Mark, 
 
Thank you for using Syncfusion controls. 
 
We have analyzed your query, SfDataGrid supports different types of SelectionMode (Single, Multiple, Extended and None). By default, you can able to de-select the selected row in Multiple selection mode. So, could you please share which SelectionMode is you have used in your application, that will help us to provide the better solution. 
 
 
Regards, 
Farjana Parveen A  



MA Mark August 27, 2019 04:08 PM UTC

My SfDataGrid's SelectionMode is Single. Thank You.


FP Farjana Parveen Ayubb Syncfusion Team August 28, 2019 07:25 AM UTC

Hi Mark, 
 
Thank you for your update. 
 
We have analyzed your query, currently we don’t have a support for de select the selected row in Single SelectionMode in SfDataGrid, but you can achieve your requirement by set the SelectedItem as null in PreviewMouseUp event in SfDataGird. 
 
Please refer the below code example 
 
dataGrid.PreviewMouseUp += dataGrid_PreviewMouseUp; 
void dataGrid_PreviewMouseUp(object sender, MouseButtonEventArgs e) 
{ 
    var record = this.dataGrid.GetRecordAtRowIndex(dataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex); 
    if (dataGrid.SelectedItems.Contains(record)) 
        dataGrid.SelectedItem = null; 
} 
 
 
We have considered to provide support for “Support to deselect a record in single selection mode” in WPF and logged feature request for the same. We will implement this feature in any of our upcoming release.  
 
At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We will let you know when this feature is implemented. We appreciate your patience until then. 
 
Thank you for requesting this feature and helping us define it. We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts. 
 
 
Note: The provided feedback link is private and you need to login to view this feedback. 
 
If you have any more specification/suggestions to the feature request, you can add it as a comment in the portal and cast your vote to make it count. 
 
Regards, 
Farjana Parveen A 



MA Mark September 5, 2019 03:50 AM UTC

Thanks but unfortunately it's not working the way I need it to, it sets the selected item to null NO MATTER WHERE I do the mouse up event instead of just working if I mouse up on top of the selected row.


FP Farjana Parveen Ayubb Syncfusion Team September 5, 2019 10:03 AM UTC

Hi Mark, 
 
Sorry for the inconvenience caused. 
 
You can get the row index from PointToCellRowColumnIndex method and set the SelectedItem as null, instead of get the row index from CurrentCell. 
 
Please refer the below code example 
 
dataGrid.PreviewMouseUp += dataGrid_PreviewMouseUp; 
void dataGrid_PreviewMouseUp(object sender, MouseButtonEventArgs e) 
{ 
    var rowIndex = dataGrid.GetVisualContainer().PointToCellRowColumnIndex(e.GetPosition(dataGrid.GetVisualContainer())).RowIndex; 
    var record = this.dataGrid.GetRecordAtRowIndex(rowIndex); 
    if (dataGrid.SelectedItems.Contains(record)) 
        dataGrid.SelectedItem = null; 
} 
 
 
Please let us know if you need any further details on this. 
 
Regards, 
Farjana Parveen A 



MA Mark September 5, 2019 11:06 AM UTC

Perfect! Thank you, that did the trick.


FP Farjana Parveen Ayubb Syncfusion Team September 6, 2019 06:02 AM UTC

Hi Mark, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Farjana Parveen A 


Loader.
Live Chat Icon For mobile
Up arrow icon