DataBinding and ErrorProvider - How to provide custom error messages?
We use BusinessObjects, implementing IDataErrorInfo
and IEditableObject
. BindingList
s with those Objects are added to BindingSources, those are used to bind UserControls and DataGrids on the forms (WinForms). The BindingSource
is additionally set as DataSource to the ErrorProvider
of the form.
We do use currently TextBoxes for Properties of Type int and short. They are validated inside the BusinessObjects with custom validation, like min/max values, etc. That works fine, since error message form our custom validations show up nicely next to the TextBox.
However, if the input is greater than the value of an int (e.g. "9999999999") the BindingSource doesn't even try to enter that Value into the BusinesObject but instead gives the errormessage to the errorprovider like "The value for Int32 was too big.". We do n开发者_开发知识库ot want to bother our users with "Int32" but want a custom errormessage for that.
It is nice, that the BindingSource does provide this feature, but is it possible to provide custom error messages for this?
You need to set FormattingEnabled property to false to disable error-handling behaviour.
Like this:
textBox1.DataBindings.Add("Text", bindingSource1, "IntValue", false,
System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
精彩评论