AdvancedErrorProvider Class

An ErrorProvider with a SetMessage event, which is triggered if the DataSource property is set and the message of a bound property is about to be retrieved. It also fixes the scaling of the displayed icon if the Icon property is explicitly set.

See the online help for an example.

Definition

Namespace: KGySoft.WinForms.Components
Assembly: KGySoft.WinForms (in KGySoft.WinForms.dll) Version: 5.0.1
C#
[ToolboxBitmapAttribute(typeof(ErrorProvider))]
public class AdvancedErrorProvider : ErrorProvider
Inheritance
Object    MarshalByRefObject    Component    ErrorProvider    AdvancedErrorProvider

Remarks

If the original ErrorProvider is used with WinForms data binding (by setting the DataSource property), the bound items must implement the IDataErrorInfo interface to make the error messages appear on the controls. The AdvancedErrorProvider class allows customizing this behavior by providing a SetMessage event, which can be handled to allow the messages to be retrieved from any custom source.

If the bound objects implement the IDataErrorInfo interface, the error messages are preinitialized in the SetMessageEventArgs.Message property when the SetMessage event is raised.

  Tip

To provide error/message/info messages for objects, create three instances of this class. Set their icon accordingly (you can use the properties of the Icons class from KGySoft.Drawing), and handle the SetMessage event. You can derive the bound objects from the ValidatingObjectBase class (or implement the IValidatingObject interface) to provide error/warning/info messages for the bound properties. See also the Examples section for an illustration.

If you explicitly set the Icon property, and the IconSizeMode property is not SystemDefault, the AdvancedErrorProvider component ensures that the icon is scaled correctly on all platform targets. See the Remarks section of the IconSizeMode property for more details.

Examples

The following image illustrates how to use three AdvancedErrorProvider instances to provide error, warning and info messages for controls by using data binding, and deriving the items from the ValidatingObjectBase class:

Error/Warning/Info providers in the KGySoft.WinForms.Example application

  Tip

The image above is from the example application, where you can find the source code of At the Releases page of the project repository you can download it as executable binaries as well. The example is located under the Misc Tests / AdvancedErrorProvider example menu.

Constructors

AdvancedErrorProvider Initializes a new instance of the AdvancedErrorProvider class with default settings.
AdvancedErrorProvider(ContainerControl) Initializes a new instance of the AdvancedErrorProvider class attached to a container.
AdvancedErrorProvider(IContainer) Initializes a new instance of the AdvancedErrorProvider class attached to an IContainer implementation.

Properties

ContainerControlGets or sets a value indicating the parent control for this ErrorProvider.
Icon Gets or sets the icon for this AdvancedErrorProvider. Explicitly set icons can be scaled automatically, depending on the IconSizeMode property.
See the Remarks section of the IconSizeMode property for details.
IconSizeMode Gets or sets the icon sizing behavior for explicitly set icons.
Default value: AutoScale.
ShowBindingErrors Gets or sets whether binding errors should be shown by this AdvancedErrorProvider.
Default value: .

Methods

Dispose Releases this AdvancedErrorProvider instance.
(Overrides ErrorProviderDispose(Boolean))
OnSetMessage Raises the SetMessage event.
UpdateBinding Provides a method to update the bindings of the DataSource, DataMember, and the error text.

Events

SetMessage Occurs when the DataSource property is set and the message of a bound property is about to be retrieved.

See Also