We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

GDBG Undo

Thread ID:

Created:

Updated:

Platform:

Replies:

18368 Aug 28,2004 09:17 PM Sep 2,2004 01:22 AM Windows Forms 7
loading
Tags: GridControl
Lori S. Pearsall
Asked On August 28, 2004 09:17 PM

I''m seeing an odd behavior with Undo. Here''s an example : Cell 2,2 has a value of "One". I change it to "Two" and tab out of the cell (I''m still on the same row). I then execute an Undo and the focus goes back to Cell 2,2 and the value changes back to "One". I then tab out of the cell again (still on the same row) and the TEXT GOES BACK TO "TWO"? This doesn''t occur if you''ve left the row before you do the Undo. Is this expected behavior? Also, is it just typically recommended to turn off Undo/Redo for the current sorted column? I''ve noticed that if a change is done that causes the RowIndex of the record to change, an Undo affects the wrong record.

Administrator [Syncfusion]
Replied On August 29, 2004 07:41 AM

In the situation you described, I think if you do the undo twice you will see the undo ''stick'' when you leave the cell. The reason is that the grid is caching the values while you make changes to a row. The undo action on teh grid.model does not interact with the cache of saved editing row values. And when you leave teh cell, the cach value is put back into the cell which is undoing your change. In a simple sample, handling CurrentCellMoved and ending the edit on the binder forces the cached value to be cleared and makes the undo ''stick.'' Maybe something like this will work for you.
private void gridDataBoundGrid1_CurrentCellMoved(object sender, GridCurrentCellMovedEventArgs e)
{
	if(this.gridDataBoundGrid1.Binder.IsEditing)
		this.gridDataBoundGrid1.Binder.EndEdit();
}
As for as sorting, I think you would have to clear the undo/redo stacks after a sort. The undo information would no loner be valid. The grid does not try to maintain undo/redo information for sorting. If you want support undoing a sort, you would have to create a custom undo command to manage this. Here is a forum thread with a sample. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=17487

Lori S. Pearsall
Replied On August 29, 2004 06:49 PM

I''ll try out your suggestion to #1. I think you misunderstood my question about sorting. Here''s an example : I have a grid sorted by the first column which is a date. I make a change to what is currently the date in the third row, causing it to become the fifth row because of the active sort. I then do an "Undo" - this still changes the value in the THIRD row of the grid even though it''s no longer the same row. >In the situation you described, I think if you do the undo twice you will see the undo ''stick'' when you leave the cell. The reason is that the grid is caching the values while you make changes to a row. The undo action on teh grid.model does not interact with the cache of saved editing row values. And when you leave teh cell, the cach value is put back into the cell which is undoing your change. > >In a simple sample, handling CurrentCellMoved and ending the edit on the binder forces the cached value to be cleared and makes the undo ''stick.'' Maybe something like this will work for you. >
>private void gridDataBoundGrid1_CurrentCellMoved(object sender, GridCurrentCellMovedEventArgs e)
>{
>	if(this.gridDataBoundGrid1.Binder.IsEditing)
>		this.gridDataBoundGrid1.Binder.EndEdit();
>}
>
> >As for as sorting, I think you would have to clear the undo/redo stacks after a sort. The undo information would no loner be valid. > >The grid does not try to maintain undo/redo information for sorting. If you want support undoing a sort, you would have to create a custom undo command to manage this. Here is a forum thread with a sample. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=17487

Administrator [Syncfusion]
Replied On August 30, 2004 04:29 AM

The sorted DataView is moving the value, and the default support for undo/redo has no knowledge of this move. It is saving its change information by row, col which is not sufficient in this situation. If you want to try to support undo/redo in the situation, you will have to add a custom command object to the undo stack. A couple of options. You could probably listen to the dataview.ListChanged event and try to do something there on the move. Or, you could add your own change command to the undo stack that tries to tie the change to something like the columnname and a primary id value instead of the column number and the row number.

Lori S. Pearsall
Replied On August 30, 2004 11:22 AM

Hi Clay, The suggested code in the CurrentCellMoved event worked great - thanks! OK, one more Undo question. I have a derived control based on the StaticCellRenderer for one of my columns. This control uses a dropdown form to gather several pieces of information and combines them into a string which is displayed in the grid cell (the cell itself is not editable). There does seem to be 2-3 commands placed on the Undo stack when a value changes in this column, but none of them successfully changes the value back - what needs to be done to accomplish this? Plan B - I tried a second approach to this column as well. I turned off Undo for this column and created my own GridCurrentCellValueCommand and pushed it on the CommandStack. With this approach, executing an Undo DID change the string value but as soon as I tabbed out of the field the value changed back (despite that new code that you suggested for CurrentCellMoved). In addition, I can find no event that fires when the string changes to the correct value. I''m willing to explore either approach - either letting the grid push it''s own commands onto the stack or doing it myself. I just need some info on how to make the changes "stick".

Administrator [Syncfusion]
Replied On August 30, 2004 11:36 AM

I think you will likely have to use plan B. Try making this.gridDataBoundGrid1.Binder.EndEdit(); part of the code that your command.Execute method does so that it gets hit in your undo.

Lori S. Pearsall
Replied On September 2, 2004 12:18 AM

I implemented the following code that you suggested to get around the problem with Undo & cached values : private void gridDataBoundGrid1_CurrentCellMoved(object sender, GridCurrentCellMovedEventArgs e) { if(this.gridDataBoundGrid1.Binder.IsEditing) this.gridDataBoundGrid1.Binder.EndEdit(); } Unfortunately, while this solved the immediate problem, it causes others. Since my grid is sorted, the record that the user is editing now "moves" to a different row because of the EndEdit and my active sort (very confusing for the user). This, combined with the Undo/sort problem of undoing the wrong cell is leading me towards turning off Undo entirely and storing my own commands on the stack. That would allow me to store a primary key to identify the actual row I need to update. OK ... now to my question. If I implement my own command - what should I be updating in order to get around the cached values problem - do I put the "undo" value into : - grid.Model[Row,Col].CellValue - grid.CurrentCell.Renderer.ControlValue - something else? to update the "cached" value so that it doesn''t revert back when I tab out of the cell?

Administrator [Syncfusion]
Replied On September 2, 2004 01:22 AM

Try grid.CurrentCell.Renderer.Control.Text. Also, you might try calling grid.CurrentCell.NotifyChanging() to make sure teh grid is notified that the cell is changing so it can change its state members as well.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;