简体   繁体   中英

Tracking row changes in the GridControl in DevExpress C#

I have an issue that I have been banging my head against for too long now, and I can't seem to come across a solution.

We are using DevExpress, and we have a message based architecture that dispatches messages letting other components of the system know of specific changes.

Much of our application revolves around changes made to grid controls that are bound to DataTable objects.

One of the more important messages that we need to dispatch is when a row changes on our grid control. So if any value on the row changes, we want to dispatch a message with the old row values, and the new row values so we have a record of old and new. We want this to happen when the row loses focus rather than just after any value is changed immediately. This is so somebody can change the whole row before it sends a message.

The current solution I am using does not work, and is not even worth explaining.

Essentially, I need to obtain a Key/Value list of row value and column names for both the old row, and new row.

I am not sure how to do this in DevExpress.

One idea for this would be to use the row indexes provided by DevExpress grids. Once you have the row index of the changed row, you can do whatever you want with it (cast into an object, save the data stored in the row, highlight the row, etc) using this row index. This is how you access the indexes of the selected rows in a grid:

List<int> rowHandles = gridView.GetSelectedRows().ToList();    

You could make a BindingList with the data from your DataTable. You need a new class then and each object represents a Row in your DataTable. Then you add each object to a BindingList and use this as DataSource. Now the BindingList.ListChanged Event will fire foreach changed value in the grid. It give you access on old and new value. Maybe you have to implement the INotifyPropertyChanged interface in your class to know if a cell is changed.

I think you should use aspxgridview.rowupdating event which would give you both old and new values by the properties e.OldValues and e.NewValues.

So by that you can have both the values for your records.

For more detailed explaination I would recommend you to visit following links: (I hope it helps)

http://www.devexpress.com/Support/Center/Question/Details/Q314701

http://www.devexpress.com/Support/Center/Question/Details/Q261712

http://www.devexpress.com/Support/Center/Question/Details/Q293847

http://www.devexpress.com/Support/Center/Question/Details/Q350500

http://www.devexpress.com/Support/Center/Question/Details/B202180

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM