How to get SfDataGrid Row IsSelected property

In datagrid, I can use DataGridRow.IsSelected.In SfDataGrid, VirtualizingCellsControl do not has IsSelected property.How can I get this property?

3 Replies

MK Muthukumar Kalyanasundaram Syncfusion Team October 17, 2017 03:48 AM UTC

Hi Renruofan, 

Thank you for contacting Syncfusion support. 

We have checked your query. You can get the IsSelectedRow  property from dataRow of VirtualizingCellsControl as like below code.  

Code Snippet: xaml 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    //Get the Current Row and Column index from the CurrentCellManager 
    var rowColumnIndex = this.datagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex; 
    var nodeEntry = datagrid.GetNodeEntry(rowColumnIndex.RowIndex); 
    if (!nodeEntry.IsRecords) 
        return; 
    var recordUnderMouse = nodeEntry as RecordEntry; 
    // Get the DataRow 
    var dataRow = this.datagrid.GetRowGenerator().Items.FirstOrDefault(row => (row.RowType != RowType.HeaderRow && (row.RowData as Person) == recordUnderMouse.Data as Person)) as DataRowBase; 
    //Get the IsSelectedRow property from dataRow 
    var isSelected = dataRow.IsSelectedRow; 
    // To display the selected row first name  
    if (isSelected && (dataRow.Element is VirtualizingCellsControl)) 
        MessageBox.Show((dataRow.RowData as Person).FirstName); 
} 

Please find the sample from the below link and let us know if this helps you. 

Please let us know if you have any other questions. 

Regards, 
Muthukumar K 



RE renruofan November 1, 2017 06:03 AM UTC

Hi Muthukumar K,

Thanks for your reply.

You save my day!

I've used dependency property to solve this problem in MVVM Patern.



MK Muthukumar Kalyanasundaram Syncfusion Team November 2, 2017 05:21 PM UTC

Hi Renruofan,   
 
Thanks for the update. Please let us know if you need any other assistance.   
 
Regards,  
Muthukumar K 


Loader.
Up arrow icon