Hello,
I am using xamdatagrid, bound to a datatable.defaultview. When a cell value was changed, the datatable rowstate doesn't go to modifed. Only when the focus of the row is lost, the row state is changed.
How can I apply the values to the underlying datatable when a cell value has changed?
Hello Markus,
This is the default behavior for .NET databinding. Rows will not be marked as modified until the control being used to edit looses focus, or the changes are manually committed.
If you would like the changes to take effect immediately, You may force the update to happen using this code during the DataValueChanged event.
private void grid1_DataValueChanged(object sender, Infragistics.Windows.DataPresenter.Events.DataValueChangedEventArgs e) { DataRecord record = e.Record; if (record != null) { DataRowView view = record.DataItem as DataRowView; DataRow row = view.Row; row.EndEdit(); label1.Content = row.RowState.ToString(); } }}
I am attaching a sample project illustrating the suggested approach for your reference. Please let me know if you have any other questions or concerns on this matter.
Sincerely,Tihomir TonevAssociate Software DeveloperInfragistics
4010.XamDataGridImmediateChanges.zip
After further investigation, I can also suggest using DataItemUpdateTrigger and setting its property to OnCellValueChange. This will push the data to be updated while still having the control on focus. More information about our API can be found on our website here.
Thanks for the info.
When setting the cell value with an editor both suggestion didn't work but I found a solution based on your inputs.
Now it is working. Thanks!
private void XamDataGrid_EditModeStarted(object sender, Infragistics.Windows.DataPresenter.Events.EditModeStartedEventArgs e) { if (e.Editor is XamNumericEditor) { var numEditor = e.Editor as XamNumericEditor; double? value = null; if (numEditor.Value != null && numEditor.Value.GetType() != typeof(DBNull)) value = Convert.ToDouble(numEditor.Value); Task.Run( delegate () { Dispatcher.Invoke( delegate () { NumKeyPad.Show(numEditor, value, false, delegate (double? newValue) { numEditor.Value = newValue; numEditor.EndEditMode(true, true); DataRowView view = e.Cell.Record.DataItem as DataRowView; DataRow row = view.Row; row.EndEdit(); }, isAllowNull: true); }); }); } }