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
Found a bug in my IBindingList implementation that was causing the asterisk not to show. Here is my routing for checking all cells of all rows of all grids in a given window for validation errors.
Dim dataObj = DirectCast(cvp.DataContext, Infragistics.Windows.DataPresenter.DataRecord).DataItem
Dim prop As System.Reflection.PropertyInfo = dataObj.GetType.GetProperty(cell.Field.Name)
If prop IsNot Nothing Then
dataObj.GetType.GetMethod("onPropertyChanged").Invoke(dataObj, {cell.Field.Name})
If cvp.HasDataError Then
currentErrors = currentErrors & vbCrLf & "Row " & (record.DataItemIndex + 1) & " " & cvp.DataError.ToString
valid = False
End If
For c = 0 To VisualTreeHelper.GetChildrenCount(parent) - 1
'Check children of this visual object
If Not areGridsValid(VisualTreeHelper.GetChild(parent, c)) Then