I'm stuck with some legacy code that I want to upgrade a bit. I want to change the way the ErrorProvider
shows the error status on a Control. Default behavior is the Icon, and a ToolTip
if you hover on the icon.
I would like to change this behavior to be more similar to what we use in our WPF controls. Which is a red back-color(Salmon pink) and the tool-tip on the control itself.
Any tips, links or some way forward
EDIT. See my answer below, on what i ended up with.
Thank you Reza Aghaei. This is what i came up with based on your comment and some additional searching... Some of this code comes from msdn resource
ErrorProvider
component doesn't support this feature and if you need it you can create it yourself.You can subscribe to
BindingComplete
event of aBindingManagerBase
and then you can use the event arg which is of typeBindingCompleteEventArgs
that contains some useful properties:ErrorText
to determine if there is an error in data-bindingBinding.Control
to determine the control which is bounded toThese are enough for us to implement our solution.
Code
Here is a sample code which shows how can you handle
BindingComplete
event and use it to changeBackColor
and tool-tip of a control based on it's valid or invalid state.Suppose you have a binding source,
myBindingSource
which is bound to aSampleModel
class which is implementedIDataErrorInfo
. You can subscribe toBindingComplete
event ofthis.BindingContext[this.myBindingSource]
: