How do you change cell value in OnCurrentCellEndEdit

In the OnCurrentCellEndEdit event I want to alter the value the user entered and then save that value in the cell.


For example, if the e.NewValue is "123:456" I want to modify the value and put "123456" into the cell.

My grid item source is a data table and the following code does not work.


var record = dataGrid.GetRecordAtRowIndex(e.RowColumnIndex.RowIndex);

if (record is DataRowView dataRowView)

{

    dataRowView[e.RowColumnIndex.ColumnIndex] = newValue;

}




3 Replies

LN Lakshmi Natarajan Syncfusion Team November 9, 2021 01:53 PM UTC

Hi Matthew, 
 
Thank you for contacting Syncfusion support. 
 
We have checked the reported query “How do you change cell value in OnCurrentCellEndEdit” from our side. We would like to inform you that you can overcome the reported scenario by using DataTable.AcceptChanges method.  
 
Please refer to the following code snippets for more reference, 
 
private void gridTimesheet_CurrentCellEndEdit(object sender, GridCurrentCellEndEditEventArgs e) 
{ 
    var table = dataGrid.ItemsSource as System.Data.DataTable; 
    var record = dataGrid.GetRecordAtRowIndex(e.RowColumnIndex.RowIndex); 
 
    if (record is DataRowView dataRowView) 
    { 
        Device.BeginInvokeOnMainThread(() => 
        { 
            dataRowView[e.RowColumnIndex.ColumnIndex] = newValue; 
            table.AcceptChanges(); 
        }); 
    } 
} 
 
Please let us know if you need further assistance. 
 
Lakshmi Natarajan 
 



MR Matthew Rames November 9, 2021 02:09 PM UTC

That worked great, thanks for the quick reply!



LN Lakshmi Natarajan Syncfusion Team November 9, 2021 02:17 PM UTC

Hi Matthew, 
 
Thank you for the update. 
 
We are glad that our solution meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out. 
 
Lakshmi Natarajan 
 


Loader.
Up arrow icon