开发者

DataBinding: Validate before change

[.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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜