Validation 'before' setting value or issuing command
-
Greetings, I am relatively new to WPF and have an issue relating to validation with DataGrid control. I have read this article (http://msdn.microsoft.com/en-us/magazine/ff714593.aspx) which covers three different ways to validate, but none of them seem to address how to prevent setting a value or calling a undo/redo command before all validation is carried out. I want to ensure that only positive numbers can be entered into the cells. I have set a validation rule that checks if the cell contains a negative number, and I handle the DataGrid's CellEditEnding event to know when to actually change the number used in the model layer. The problem is that CellEditEnding is called before the validation rule. By the time the validation rule catches the problem, the number in the model has already been set. What I need is CellEditEnded, but it appears this event only exist in the Silvelight version of DataGrid. Any ideas? :confused: Thanks
-
Greetings, I am relatively new to WPF and have an issue relating to validation with DataGrid control. I have read this article (http://msdn.microsoft.com/en-us/magazine/ff714593.aspx) which covers three different ways to validate, but none of them seem to address how to prevent setting a value or calling a undo/redo command before all validation is carried out. I want to ensure that only positive numbers can be entered into the cells. I have set a validation rule that checks if the cell contains a negative number, and I handle the DataGrid's CellEditEnding event to know when to actually change the number used in the model layer. The problem is that CellEditEnding is called before the validation rule. By the time the validation rule catches the problem, the number in the model has already been set. What I need is CellEditEnded, but it appears this event only exist in the Silvelight version of DataGrid. Any ideas? :confused: Thanks
greekgoddj wrote:
I am relatively new to WPF
Yup got that right you are posting in the wCf forum :laugh: This is not going to help with your problem because I think it is a design issue. This is how I get around it. I never allow inline editing - a datagrid is a display tool only, I either pop a dialog or user another form or use a detail control (haven't got that one worked out yet) to do the editing. This gives me complete control of the object, I have a static method in my viewmodelbase that copies the selected object out of the list<> into the EditableObject. This is them bound to the editing control. If the user cancels I simply throw the editable object away. Save writes the object back to the database and also copies (for edit) the editable object to the selected object. Once again a static method. Caveat the lookup values in the selctedobject need to be retrieved if you do not refresh the list.
Never underestimate the power of human stupidity RAH