What's going wrong:
When I edit a cell in a SpreadsheetGear WorkbookView, and initiate the CellEndEdit event by either hitting Enter, Tab, or any of the arrow keys, the value I just typed is wiped out.
Context:
- It seems that when editing a cell in a WorkbookView, a control is added on top of the WorkbookView that behaves like a TextEdit to allow you to type in your data. When the CellEndEdit event happens, the call stack indicates that the WorkbookView calls ControlCollection.Remove(...).
- This, in turn, causes the Form to give focus to another control on the page. The page in question includes some TextEdit controls above the WorkbookView that are inherited from a base page. The first TextEdit is given focus for a brief moment.
- Validation is set up on these TextEdits which ends up initiating a model update. This wipes out what is in the WorkbookView because all this happens before the change in view is pushed to the model.
Questions:
Is there a way to stop the other controls from receiving focus before my WorkbookViews event handlers can push the view's changes to the model? Or is there another way to handle this better?
Please let me know if I can elaborate anywhere or explain myself better, thanks!
Update:
I created a test application with one DevExpress TextEdit and one SpreadsheetGear WorkbookView. If I add textEdit1_Validated and textEdit1_Enter, I get the same behavior. The focus goes to the TextEdit control which now seems to be due to the validation handler.
Apparently the DevExpress TextEdit control's validation handler requests focus, and it was an issue with one of the statements that was run during the model update. The view's Property for the data in the SpreadsheetGear WorkbookView was being set to the model's version of this property, and the model can either have default values or user defined values.
The statement read something like this:
I changed the statement to read something like this:
This solved the issue because if the data being entered is user defined, the user is typing in the data, and this if statement allows the view to hold onto that data until after the validation of basically the whole page. Still on the callstack is the update to the model for specifically this Data property.
I'm sorry that this probably won't offer much help to people in general as it was an issue with personal implementation. But I still think it is worth noting that if you tie a major update to a validation handler, something like this is bound to happen later on down the road with more and more additional update statements.