Bind nullable DateTime to MaskedTextBox

后端 未结 5 1595
遇见更好的自我
遇见更好的自我 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:22

    Experimenting with this i finally found an easier solution to this.

    STEP 1:

    Search the line that is binding your maskedtextbox (mine's called "mTFecha") in your Form.Designer.cs. i.e:

     // mTFecha
     // 
     this.mTFecha.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.listaAnimalesOfertadosBindingSource, "F_peso", true);
    

    STEP 2:

    Apply a minor hack:

    this.mTFecha.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.listaAnimalesOfertadosBindingSource, "F_peso", true, System.Windows.Forms.DataSourceUpdateMode.OnValidation, "  /  /"));
    

    You're Done!

提交回复
热议问题