开发者

DataBinding and ErrorProvider - How to provide custom error messages?

开发者 https://www.devze.com 2022-12-25 14:15 出处:网络
We use BusinessObjects, implementing IDataErrorInfo and IEditableObject. BindingLists with those Objects are added to BindingSources, those are used to bind UserControls and DataGrids on the forms (Wi

We use BusinessObjects, implementing IDataErrorInfo and IEditableObject. BindingLists 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号