如何在Windows应用程序中为datetimpicker设置验证 [英] How I can set validation for datetimpicker in windows application

查看:83
本文介绍了如何在Windows应用程序中为datetimpicker设置验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我的表单中有一个datetimepicker控件,如果没有从datetimepicker中选择日期,则想设置验证。但问题是在日历中总是选择默认(今天的日期)我可以做什么验证。



我尝试过:



i想要设置验证如果没有选择日期请选择日期。

hello
i have a datetimepicker control in my form and want to set validation if date is not selected from datetimepicker. but the problem is the default(today date) was always selected in the calendar what can i do for validation.

What I have tried:

i want to set validation if date is not selected please select the date.

推荐答案

做的在你的加载事件下面。



do the below on your load event.

dtpYourControlID.CustomFormat = " "
dtpYourControlID.Format = DateTimePickerFormat.Custom





这将将值设置为空字符串。您可以在要应用验证的位置检查此空状态。

(根据此值的条件验证)



现在位于用户选择日期的地方(DateTimePicker1_ValueChanged事件)。将格式设置回正确的日期时间格式。





This will set the value to empty string. you can check for this empty condition on the location where you want to apply validation.
(Validate on the basis of if condition on this value)

now at the place, where user selects date(DateTimePicker1_ValueChanged event). set the format back to proper date time format.

dtpYourControlID.CustomFormat = "dd/MM/yyyy hh:mm:ss"


这篇关于如何在Windows应用程序中为datetimpicker设置验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆