Re-validating DataGrid after programmaticallychanging row source
-
Validation in Windows Presentation Foundation[^] and http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^] were both good resources for custom validation rules on a DataGrid, but if I programmatically change values in the row source, the row doesn't re-validate. If I change a cell value by manually editing it, on the other hand, validation will fire. How can I force validation even when the user is not directly manipulating the cell? I have my custom validation rule ValidationStep set to CommittedValue and UpdatedValue. I've also tried BeginEdit and CommitEdit after changes are made. Any thoughts?
-
Validation in Windows Presentation Foundation[^] and http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^] were both good resources for custom validation rules on a DataGrid, but if I programmatically change values in the row source, the row doesn't re-validate. If I change a cell value by manually editing it, on the other hand, validation will fire. How can I force validation even when the user is not directly manipulating the cell? I have my custom validation rule ValidationStep set to CommittedValue and UpdatedValue. I've also tried BeginEdit and CommitEdit after changes are made. Any thoughts?
Does the class representing a row of data implement and use the INotifyPropertyChanged interface?
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Does the class representing a row of data implement and use the INotifyPropertyChanged interface?
Mark Salsbery Microsoft MVP - Visual C++ :java:
It's an EF ComplexObject using the default auto generated code. It is derived from StructuralObject, which is derived from INotifyPropertyChanging and implements the INotifyPropertyChanged. I checked the Properties I'm changing and they all call the ReportPropertyChanged method after a change occurs. I think this has more to do with the way I'm updating the row source. I'm allowing the user to open a context menu through the ValidationErrorTemplate and select various options. The change occurs in the MenuItem click event. If I change focus to anything in the Window using the mouse, the row will validate.
-
It's an EF ComplexObject using the default auto generated code. It is derived from StructuralObject, which is derived from INotifyPropertyChanging and implements the INotifyPropertyChanged. I checked the Properties I'm changing and they all call the ReportPropertyChanged method after a change occurs. I think this has more to do with the way I'm updating the row source. I'm allowing the user to open a context menu through the ValidationErrorTemplate and select various options. The change occurs in the MenuItem click event. If I change focus to anything in the Window using the mouse, the row will validate.
The validation system is really for validating user input so there's not an easy provision for validating code-produced data, since that data should be validated by the code anyway. You may find a solution in these... Validation Rules for WPF and C#[^] force a Binding to validate[^]
Mark Salsbery :java:
-
The validation system is really for validating user input so there's not an easy provision for validating code-produced data, since that data should be validated by the code anyway. You may find a solution in these... Validation Rules for WPF and C#[^] force a Binding to validate[^]
Mark Salsbery :java:
You're right. I'm not using the validator as intended. There are plenty of things I can do in a cell data template to get my intended functionality. Thanks for the help. It didn't get me to my original goal, but illuminated the error of my ways and saved me time digging for an answer that doesn't exist.