无法跳出数据绑定的 Winforms 日期时间选取器



致力于构建具有多个数据绑定控件的表单,并注意到不能离开表单上的日期时间选择器或组合框。

        // signoutAfterDateTimePicker
        // 
        this.signoutAfterDateTimePicker.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.clientBindingSource, "SignoutAfter", true));
        this.signoutAfterDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Time;
        this.signoutAfterDateTimePicker.Name = "signoutAfterDateTimePicker";

由于我在日期时间选择器上找不到任何内容,但发现了与无法从数据绑定的 Winforms 下拉列表中选项卡类似的问题。 因此发布了此链接,讨论如何修复下拉列表。 认为那些有日期时间选择器问题的人也会发现该链接很有用。

解决方法是将"原因验证"设置为 false。

this.signoutAfterDateTimePicker.CausesValidation = false;

当然,您可能希望实际验证。

答案是将 CausesValidation 设置为 False - 就像上面的链接所建议的那样。

最新更新