Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to make GridControl immediately save changes in a cell after editing

$
0
0

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.

Added By: Gregory Colton at: 9/25/2013 9:16:28 AM    

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 PM    

Even 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 AM    

Works 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();}}

Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>