问题描述
我有两个日期选择器,一个有开始日期,另一个有结束日期。
开始日期datepicker1)结束日期(datepicker2)
当我点击datepicker1中的第7个星期一日期时,自动12月星期六显示在datepicker2中。
工作正常。
i有一个验证datepicker1怎么办。
在datepicker1中总是用户只选择星期一,如果用户选择任何其他日期将显示消息选择星期一。
如何在datepicker中的csharp中进行验证。
i have two date picker, one has start date and another one has End date.
Start date datepicker1) End date(datepicker2)
when i click the 7th Monday date in datepicker1 automatically 12th Saturday is displayed in the datepicker2.
that is working fine.
i have one validation datepicker1 how to do.
in the datepicker1 always user choose the day Monday only, if user choose any other day will display the message choose the Monday .
how to do that validation in csharp in datepicker.
推荐答案
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
DateTime dt = dateTimePicker1.Value;
if (dt.DayOfWeek != DayOfWeek.Monday)
{
while (dt.DayOfWeek != DayOfWeek.Monday)
{
dt = dt.AddDays(-1);
}
}
dateTimePicker1.Value = dt;
}
P.S。我不建议这样做,因为这是非常脏的方法。我建议你在更改时验证日期并让用户知道问题,以便他可以选择星期一。
P.S. i would not recommend doing this, as this is pretty dirty approach. I would suggest you validate the date when changed and let the user know the problem so that he can select a Monday.
这篇关于在Windows应用程序中使用csharp进行Datepicker验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!