开发者

DataBinding: Validate before change

开发者 https://www.devze.com 2022-12-18 22:53 出处:网络
[.NET 2] Situation: class MyObject { string Max { get{...}; set{...}; } string Min { get{...}; set{...}; }

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

精彩评论

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