sfDataGrid - get row when checkbox changed

I have a datagrid with checkbox column (editable). When checkbox is clicked I want to update database. But for that I need the value from the "ListId" and "Name" column for the row.

I tried using the CellCheckBoxClick event, and I am able get the rowIndex. But CellCheckBoxClickEventArgs does not contain DataRow property.

So how do I get the row and values from other columns in the row.

3 Replies 1 reply marked as answer

SS Susmitha Sundar Syncfusion Team July 1, 2020 04:25 PM UTC

Hi azhar, 
 
Thank you for using Syncfusion controls. 
 
You can get the RowData from CellCheckBoxCick event. In this event checkbox value not changed. This event raised before the value changed. You want to get the row data after value changed, you can use the SfDataGrid.View.RecordPropertyChanged. 
 
 
private void Form1_Load(object sender, EventArgs e) 
 { 
     this.sfDataGrid1.View.RecordPropertyChanged += View_RecordPropertyChanged; 
 } 
 
 private void View_RecordPropertyChanged(object sender, PropertyChangedEventArgs e) 
 { 
     if(e.PropertyName == "IsChecked") 
     { 
         var checkBoxValue = (sender as OrderInfo).IsChecked; 
         var cellValue = (sender as OrderInfo).OrderID; 
         MessageBox.Show("checkbox value: " + checkBoxValue + "\n CellValue: " + cellValue,"RecordPropertyChanged"); 
     } 
     
 } 
 
 private void SfDataGrid1_CellCheckBoxClick(object sender, CellCheckBoxClickEventArgs e) 
 { 
     var checkBoxValue = (e.Record as OrderInfo).IsChecked; 
     var cellValue = (e.Record as OrderInfo).OrderID; 
     MessageBox.Show("checkbox value: " + checkBoxValue + "\n CellValue: " + cellValue, "CellCheckBoxClick"); 
 } 
 
 
 
 
Please check the sample and let us know if you need further assistance on this. 
 
Regards, 
Susmitha s 



TS Truth Seeker October 26, 2021 02:29 AM UTC

When is the view created? In my project the view is null!



BT Balamurugan Thirumalaikumar Syncfusion Team October 26, 2021 03:43 PM UTC

Hi Truth, 
 
Thank you for interesting in Syncfusion products. 
 
We have checked your query “When is the view created? In my project the view is null!” at our end. We regret to inform you that the view will be null if the datasource is not set to SfDataGrid. So, if you are dynamically generating the datasource, there is a chance you'll get the null value for View. As a result, we suggest that you to use the DataSourceChanged event to access the View. We have prepared the simple sample. You can refer the following sample for your reference. 
 
 
Please let us know if you would require any other assistance. we will be always happy to assist you. 
 
Balamurugan Thirumalaikumar  
 


Marked as answer
Loader.
Up arrow icon