문제

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 not 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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top