[.NET 2]
Situation:
class MyObject
{
string Max { get{...}; set{...}; }
string Min { get{...}; set{...}; }
}
MyObject myObj1 = new MyObject();
// ... code
txtMin.DataBindings.Add("Text", myObj1, "Min");
txtMax.DataBindings.Add("Text", myObj1, "Max");
Problem:
Need verifying M开发者_JS百科in < Max
before changing the property in MyObject.
If OK, change, if NOK, leave as is(maybe a message to the user).
(sorry if duplicate)
Depends on what you want to do when validation fails (Min >= Max), you can use BindingComplete or Parse events from Binding.
In C# 3.5 it can be done with implementing custom ValidationRule.
精彩评论