开发者

C# datetime binding

开发者 https://www.devze.com 2022-12-13 05:39 出处:网络
I have a textbox I want to bind to DateTime property to an object : 开发者_JS百科myTextBox.DataBindings.Add(\"Text\",myObject,\"DateTimeProperty\")

I have a textbox I want to bind to DateTime property to an object :

开发者_JS百科
myTextBox.DataBindings.Add("Text",myObject,"DateTimeProperty")
myTextBox.DataBindings["Text"].FormatString = "HH:mm";
myTextBox.DataBindings["Text"].FormattingEnabled = true;
myTextBox.DataBindings["Text"].BindingComplete +=
            delegate(object sender, BindingCompleteEventArgs e)
            {
                if (e.Exception is FormatException)
                    MessageBox.Show("Wrong formating, should be :" +myTextBox.DataBindings["Text"].FormatString);
            };

This works perfectly, when I change the textbox value, the property change. Now I want the reverse (without parsing the text).

I want to add a button that increment by 1 minutes myObject.DateTimeProperty. The issue is I can't do

 myObject.DateTimeProperty.Minutes+=1;

nor

 myObject.DateTimeProperty = myObject.DateTimeProperty.AddMinutes(1);

Any ideas?


Does myobjoect implement INotifyPropertyChanged?

0

精彩评论

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