I currently use a routine to loop the data bound objects of my forms so that I can call BindingExpression.UpdateSource() and check for errors using IDataErrorInfo.
I would like to do the same thing for my xamDataGrids bound to a custom IBindingList List of custom data objects. So after about half a days worth of research on this forum I wrote the following routine and several variations.
However my validation routine never fires as the setter is never called for any of the properties of the custom data objects that I am using. I have tried several tricks to set the active cell and start and end the edit modes. I have played with some RoutedCommands with no luck. Is there any trick to getting the datagrid to fire an equivalent to UpdateSource().
Public Function areGridsValid(ByVal parent As DependencyObject) As Boolean
Dim valid As Boolean = True
For i = 0 To VisualTreeHelper.GetChildrenCount(parent) - 1
If VisualTreeHelper.GetChild(parent, i).GetType Is GetType(XamDataGrid) Then
Dim grid As XamDataGrid = VisualTreeHelper.GetChild(parent, i)
For Each record As Infragistics.Windows.DataPresenter.DataRecord In grid.Records
For Each cell As Infragistics.Windows.DataPresenter.Cell In record.Cells
Dim cvp As CellValuePresenter = CellValuePresenter.FromCell(cell)
If cvp IsNot Nothing Then
Dim be As BindingExpression = cvp.GetBindingBLOCKED EXPRESSION
Next
Return valid
End Function
Thank you
HI,
In your class, I am assuming you are implementing INotifyPropertyChange. I am also assuming your Unboundfield isbound to a property that implements INotifyPropertyChange.
If so, create a method in your customer object that calls NotifyPropertyChange on all your properties.
Sincerely, Matt Developer Support Engineer
I changed the way I call my validation routines so that I can call INotifyPropertyChanged and have an event handler perform validation. I effectively had my validation inside of the setter. I now am getting the error routines to fire and the error is being added to the IDataErrorInfo error dictionary. However, my grid does not show the red * asterisk. From reading other posts I understand that this is because the grid is not in edit mode. Can I do something about this?
Thanks
Devin
Thank you for your reply.
I am implementing INotifyPropertyChanged and all of my setters in all of my dataobjects raise the PropertyChanged event through the use of a method that I named onPropertyChanged. Similar to the example on this page http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.propertychanged.aspx
However, my issue is that if I put a breakpoint in on the setter of a property that is bound to an unboundfield in the grid and loop using the routine in my previous post, I never hit the setter. If I physically enter the field and then leave the field I will hit the breakpoint. I suppose I am trying to emulate a field edit and "endedit" within that loop routine. Let me know if any additional code would help.
Furthermore, if I bind the same data object with say a xamMaskedEditor that is on my form and not in a xamDataGrid. I then call the routine below. I will hit the breakpoint on the setter that I was expecting to hit after the line expression.UpdateSource().
EDIT: Had to replace some () with [] to not get a blocked expression message when posting this code:
Private Function areFormFieldsValid(ByVal x As DependencyObject) As Boolean
Dim localValues As LocalValueEnumerator = x.GetLocalValueEnumerator()
While localValues.MoveNext()
Dim entry As LocalValueEntry = localValues.Current
If BindingOperations.IsDataBound(x, entry.Property) Then
Dim binding As Binding = BindingOperations.GetBinding(x, entry.Property)
Dim exp As BindingExpression =
BindingOperations.GetBindingExpression [x, entry.Property]
exp.UpdateSource[]
If exp.HasError Then
currentErrors = currentErrors & vbCrLf & exp.ValidationError.ErrorContent
valid = False
End If
End While
'REMOVED RECURSIVE LOOP CODE FOR THIS POST
Thanks again.