Bind nullable DateTime to MaskedTextBox

后端 未结 5 1658
遇见更好的自我
遇见更好的自我 2021-01-18 05:59

I have a masked text box bound to a nullabe datetime, but when the date is blanked out, the validation on the masked text box won\'t complete. Is there a way to force this

5条回答
  •  遇见更好的自我
    2021-01-18 06:03

    I use this with maskedtextbox for datetime type

    this.txtDateBrth.DataBindings.Add("Text", bsAgent, "DateBrth", true, DataSourceUpdateMode.OnPropertyChanged, null, "dd/MM/yyyy");
    

    if need null date value, use nullable datetime type in class declaration :

    private DateTime? _DateBrth;
            public DateTime? DateBrth
            {
                get { return _DateBrth; }
                set { _DateBrth = value; }
            }
    

提交回复
热议问题