If there any method to use for a cell in a datagrid, such that it commits the changes to the underlying datasource as cell content change? I have a window that has a XamDataGrid with three columns, two are comboboxes and the last is a generic editor (xamTextEditor). When all three are filled in the OK button is enabled based on the underlying viewmodel. The issue is that the button is not enabled until the user either leaves the cell, or leaves the row, or hits Enter, thus comitting the row. If I put code in to trap the CellChange and end and start the editmode,
FilterGrid.ExecuteCommand(
.EndEditModeAndAcceptChanges);
.StartEditMode);
then the autoselection of the text in the xamTextEditor poses a different problem, in that the user cannot continuously edit. Is there any way around this to elegantly solve this?
Hi,
I have 9.2 library and the XamDataGrid has a property called UpdateMode, but it doesn't seems to work (OnCellChange, OnRecordChange). Is it implemented? Is there something else that should be activated for it to be working?
Besides, I workaround proposed. It works perfectly for XamTextEditor but not for XamCurrencyEditor. Could someone propose a solution?
Thank you,
Pascal
Hello,
Currently, there is no such method to commit changes on value changed of the Cell. What you can do is exactly what you are trying. To make it work correctly, you have to handle first the EditModeStarted event and set the SelectionStart and SelectionLength properties of the Editor. SelectionStart has to be set to the length of the Text, so that the caret goes to the last position. The SelectionLength has to be 0 so that no text will be selected. Then you can handle the CellChanged event and use DataPresenterCommands.EndEditModeAndAcceptChanges and StartEditMode again. Here it is with sample code:
void xamDataGrid_EditModeStarted(object sender, Infragistics.Windows.DataPresenter.Events.EditModeStartedEventArgs e)
{
(e.Editor as XamTextEditor).SelectionStart = (e.Editor as XamTextEditor).Text.Length;
(e.Editor as XamTextEditor).SelectionLength = 0;
}
void xamDataGrid_CellChanged(object sender, Infragistics.Windows.DataPresenter.Events.CellChangedEventArgs e)
xamDataGrid.ExecuteCommand(DataPresenterCommands.EndEditModeAndAcceptChanges);
xamDataGrid.ExecuteCommand(DataPresenterCommands.StartEditMode);
Debug.WriteLine(e.Cell.Value.ToString() + Environment.NewLine);
Let me know if you have questions on this.