Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.11/5 (2 votes)
See more:
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.
Posted

1 solution

I dont think we can disable certain days of week in this control. But we can force the user to get the selected day as monday of the week from which he has selected any date. This can be done like this:

C#
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. 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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900