Binding an ErrorProvider to an object with child objects
I have a type called Shipment that has an instance of type Station.
Both types implement
INotifyPropertyChanged and
IDataErrorInfoOn a Windows Form I have an error provider's DataSource set to a BindingSource of the Shipment type. I have a property of type string on the shipment type bound to a textbox. when an invalid value is entered errorprovider detects this and displays the error message.However, a property on the the Station instance(a child object of Shipment ) does not trigger the errorprovider for any errors occurring in the Station property.
Does the errorProvider only displays shallow property errors?
what is a work around?
> Does the errorProvider only displays shallow property errors?Yes
> what is a work around?
One work-around is to plumb this into the parent's IDataErrorInfo implementation (it would need to map child IDataErroInfo/INotifyPropertyChanged to the parent property).
Joe Stegman
The Windows Forms Team
Microsoft Corp.
This posting is provided "AS IS" with no warranties, and confers no rights
OK - I think I understand your issue now. The ErrorProvider will display error info if you bind to the parent property (e.g. if you bind directly to the "Station" property). If you are binding to a child property on the parent property (e.g. "Station.Name"), then the ErrorProvider will not pick up the error (basically, this binding is parented to a different BindingManager than the one the parent ErrorProvider is monitoring). To get this to work, do the following:
Add a new BindingSource
Set the BindingSource.DataSource to the ShipmentBindingSource
Set the BindingSource.DataMember to "Station" (you can type this directly into the PropertyGrid).
Add a new ErrorProvider and hook it up to this BindingSource
Bind your child controls through this BindingSource
You can also do this via Code by only adding a new ErrorProvider and setting the ErrorProviders DataSource to the ShipmentBindingSource and the ErrorProviders DataMember to "Station".
Joe Stegman
The Windows Forms Team
Microsoft Corp.
This posting is provided "AS IS" with no warranties, and confers no rights.