2009-12-02 88 views
0

我有一個文本框,我要綁定的DateTime屬性的對象:C#日期時間結合

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); 
      }; 

這完美的作品,當我改變文本框的值,屬性的變化。現在我想要反向(不解析文本)。

我想添加一個按鈕,增加1分鐘myObject.DateTimeProperty。問題是我不能做

myObject.DateTimeProperty.Minutes+=1; 

也不

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

任何想法?

+0

爲什麼你不能這樣做?有什麼問題? – 2009-12-03 13:06:57

回答

1

myobjoect實施INotifyPropertyChanged

+0

似乎他不是使用WPF,而是使用Windows Forms數據綁定。 – 2009-12-03 13:06:15

+0

我很確定INotifyPropertyChanged接口也適用於Windows窗體。如我錯了請糾正我。 – Sebastian 2009-12-03 16:20:00

+0

好吧,它的工作。我不知道我做了什麼,我的不好:p – Toto 2009-12-04 07:04:58