I'm using the PropertyGrid with various objects that implement INotifyDataErrorInfo. I was pleasantly surprised to find that the PropertyGrid hooks into this interface and displays a red border around the whole control if the SelectedObject is invalid; similarly it displays a red border around any individual properties that are invalid. However I have found a couple of issues relating to this:-
1) Within my object's property setters I perform object validation and update the INotifyDataErrorInfo members accordingly. However after changing an invalid property value to a valid value, both of these red borders remain.
My workaround is to force validation of the entire object in the PropertyGrid.PropertyValueChanged event,. This results in the red border around the whole PropertyGrid disappearing, but the red border around the property that has just been changed remains. My workaround for *this* is to set SelectedObject to null then back to my object, which seems to refresh things.
2) The PropertyValueChanged event gets raised if I change a property value then press Enter or click into a different property. However if I change a property's value then set focus to a different control, the underlying object's property gets updated but the PropertyValueChanged event doesn't fire, so I lose my "workaround" mentioned earlier. The PropertyGrid.LostFocus event doesn't seem to fire either, so I'm at a loss as to how else I can trap this situation.
Comments: ** Comment from web user: andyste1 **
1) Within my object's property setters I perform object validation and update the INotifyDataErrorInfo members accordingly. However after changing an invalid property value to a valid value, both of these red borders remain.
My workaround is to force validation of the entire object in the PropertyGrid.PropertyValueChanged event,. This results in the red border around the whole PropertyGrid disappearing, but the red border around the property that has just been changed remains. My workaround for *this* is to set SelectedObject to null then back to my object, which seems to refresh things.
2) The PropertyValueChanged event gets raised if I change a property value then press Enter or click into a different property. However if I change a property's value then set focus to a different control, the underlying object's property gets updated but the PropertyValueChanged event doesn't fire, so I lose my "workaround" mentioned earlier. The PropertyGrid.LostFocus event doesn't seem to fire either, so I'm at a loss as to how else I can trap this situation.
Comments: ** Comment from web user: andyste1 **
I've been unable to repro in a separate project so I guess it's down to my code for me to investigate. You can close this issue. Apologies.