Need Help: Undo/Redo - Windows Forms, Data Binding and Business Objects

May 8 2004 9:33 AM
Maintaining state of Business Object and User Interface to provide N-No of Undo/Redo capability. User Interface and Business Object synchronization (After any Undo/Redo operation, the UI should focus the Bound control whose value is changed). "As far as maintaining the state of the business object is concerned, this problem is resolved. But the only trouble i am facing is "The User Interface must respond and set the focus to the underlying control" Problem Description: The undo/redo action should allow user-initiated changes to be reversed and re-applied. It is necessary to detect user-initiated changes to the business object. It would be insufficient to monitor the various property change events emitted by the business object because the event handler would be unable to tell whether the change originated from the UI. Furthermore, it would be insufficient to monitor the validated event because this event provides no details about the binding activity (before/after property values). Also some modifactions to the state of the object might result from a method invocation. The requirement is to find an event which gets fired every time the Object property is changed or reset. As well as this event should notify us the current bindingContext. The binding class in .Net Framework provides us 2 such events viz Format and Parse and these two events proved to be insufficient because of their nature of occurance. (The Format event gets fired every time before and after the object properties are changed and there is no notification of New and Old values. The Parse event gets fired every time when the property is changed through the UI and will not get fired when the property is changed through the code) Research over BindingManagerBase revealed that the Push /Pull data methods are not virtual methods, they are only protected methods in BindingManagerBase, so it seems deriving from BindingManagerBase could not customize them, also the BindingContext only accepts the class which base is BindingManagerBase so create a wrapper class for the PropertyManager class also might not work In order to achieve the above mentioned objective, we are thinking of building a CommandManager which would sit between the Presentation layer and Business layer. CommandManager will be responsible for interacting with the Business layer and maintaing the UI state as well as the Business Object's current state. Any property changes/method calls to the Business Object will pass through the CommandManager. This solution requires the team developers to write their own Custom binding over the .Net Framework and seems to be a possible but too much of an effort