I am vailidating the data displayed within my datagrid using the IdataErrorInfo interface (as described in a few other posts here oin the forum). The final problem that I am having is walking the visual tree of my current UI and finding all the controls that are in an error state.
foreach (object child in LogicalTreeHelper.GetChildren(obj)) { if (child is TextBox) { TextBox element = child as TextBox;
if (element.GetBindingBLOCKED EXPRESSION I get a recordPresenter as the Child element and it has no children.....
Thanks
Hello,
You can try using our helper methods for traversing the element tree of the application:
Infragistics.Windows.Utilities.GetAncestorFromType(...);
Infragistics.Windows.Utilities.GetDescendantFromType(...);
Infragistics.Windows.Utilities.GetAncestorFromName(...);
Infragistics.Windows.Utilities. GetDescendantFromName(...);
I am writing this code in a utility class, that will be passed an object and it needs to traverse the object looking for all controls that HasErrors and recurse to child elements.
I am unsure how you would envision the helper methods being used as iterators?
I must be missing something from your post - what I need is, given a xamdataGrid - how do I traverse its visual tree to find all 'cells' that contain validation errors?
IE: bool GetValidationErrors ( List<Errors> ValidationErrors, DependencyObject ControlToCheck )
Hopefully this helps out someone in the future...
The Solution to this problem is rather simple (now that i know the solution) and does not reside with the uility FindDescendent() methods at all.
And the reason we are doing this is we have a list of errors displayed at the bottom of our screen that contain all the errors for all open edit windows, when and error is clicked, it navigates the user to the actual field that is in error - changeing ContentPanes if necessary.
To iterate through a XamDatagrid and find all of the controls that are in error - and the error message, the following can be done.
// Traverse each recordforeach (DataRecord Record in datagrid.RecordManager.Current){ // Traverse each Cell foreach (Cell currentCell in Record.Cells) { // Get the Cell's CellValuePresenter CellValuePresenter cvp = CellValuePresenter.FromCell(currentCell);
// Interrogate for errors, add to collection if necessary if (cvp.HasDataError) { string ErrorMsg = cvp.DataError.ToString(),
} }}
Hi Rod.
I know it's been a long time since you posted this, but...
Do you remember the deal with the DataError properties/methods on the CVP? Are these extension methods? How can I gain access to them in my grid?
Thanks!
These properties are exposed from the IDataErrorInfo support feature of the XamDataGrid and were first introduced and available in 9.2 release and later.
Ah ha! I'll put in a request for a renewal. Thanks for the quick and decisive assistance, Alex.