This example shows how to update GridControl DataSource right after a cell editor value has been changed. To implement this scenario, we have introduced the CommitHelper.CommitOnValueChanged attached property.
Question Comments
Added By: (no info) at: 9/6/2012 12:10:03 PM
Great example.
One thing to note --> It may be necessary to call view.ActiveEditor.EditValue = view.Grid.GetCellValue(e.RowHandle, e.Column); after the call to view.PostEditor(); to display the value that was actually stored. The problem here is, the value that actually gets stored doesn't get displayed to the user. The call to GetCellValue will show the user the value that was actually persisted.
I am getting a error stating that CommitOnValueChanged was not found in CommitHelper. Event the Example has the same error. The CommitHelper class does not have a method called CommitOnValueChanged either. Am I missing something? As it sits the example won't even compile.
Added By: Puneet Lulla at: 3/10/2014 11:37:35 PMEven i am getting the same problem like Gregory Colton. Please provide some assistance as soon as possible
Added By: Jaap Vliet at: 9/24/2014 2:11:00 AMWorks only in a Tableview, but easy to edit for a Treelistview
Added By: Alexander S (DevExpress Support) at: 9/24/2014 3:57:35 AM Hi Jaap,Since TreeListView.CellValueChanging and GridViewBase.CellValueChanging are different events, the suggested helper is not universal. And yes, it can be easily adopted to work with TreeListView. The following code is more universal:
[C#]classCommitHelper{publicstaticreadonlyDependencyPropertyCommitOnValueChangedProperty=DependencyProperty.RegisterAttached("CommitOnValueChanged",typeof(bool),typeof(CommitHelper),newPropertyMetadata(CommitOnValueChangedPropertyChanged));publicstaticvoidSetCommitOnValueChanged(GridColumnBaseelement,boolvalue){element.SetValue(CommitOnValueChangedProperty,value);}publicstaticboolGetCommitOnValueChanged(GridColumnBaseelement){return(bool)element.GetValue(CommitOnValueChangedProperty);}privatestaticvoidCommitOnValueChangedPropertyChanged(DependencyObjectsource,DependencyPropertyChangedEventArgse){GridColumnBasecol=sourceasGridColumnBase;if(col.View==null)Dispatcher.CurrentDispatcher.BeginInvoke(newAction<GridColumnBase,bool>((column,subscribe)=>{ToggleCellValueChanging(column,subscribe);}),col,(bool)e.NewValue);elseToggleCellValueChanging(col,(bool)e.NewValue);}privatestaticvoidToggleCellValueChanging(GridColumnBasecol,boolsubscribe){if(!(col.ViewisDataViewBase))return;if(subscribe){if(col.ViewisTreeListView)(col.ViewasTreeListView).CellValueChanging+=TreeCellValueChanging;else(col.ViewasGridViewBase).CellValueChanging+=GridCellValueChanging;}else{if(col.ViewisTreeListView)(col.ViewasTreeListView).CellValueChanging-=TreeCellValueChanging;else(col.ViewasGridViewBase).CellValueChanging-=GridCellValueChanging;}}staticvoidTreeCellValueChanging(objectsender,TreeListCellValueChangedEventArgse){if((bool)e.Column.GetValue(CommitOnValueChangedProperty))(senderasDataViewBase).PostEditor();}staticvoidGridCellValueChanging(objectsender,CellValueChangedEventArgse){if((bool)e.Column.GetValue(CommitOnValueChangedProperty))(senderasDataViewBase).PostEditor();}}