Click to See Complete Forum and Search --> : Disable dates on date timepicker control


New2Net
March 30th, 2004, 11:55 AM
Hi,

I am looking to create a custom date timepicker. The datetime picker disables Saturday & Sunday(Grayed out so that user can not select these 2 days). Rest of the weekdays are enabled so that user can select one.

Thanx for the help in advance!

Craig Gemmill
March 31st, 2004, 05:19 PM
For the amount of work that this would involve just to gray out and disable a couple rectangles, you would be better off creating your own datetimepicker, which isn't really worth it either.

I would just handle the CloseUp event:


Private Sub DateTimePicker1_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.CloseUp
If (DateTimePicker1.Value.DayOfWeek = DayOfWeek.Saturday) Or (DateTimePicker1.Value.DayOfWeek = DayOfWeek.Sunday) Then
'
'Now just add the right amount of days to make it Monday
'
Select Case DateTimePicker1.Value.DayOfWeek
Case DayOfWeek.Saturday
DateTimePicker1.Value = DateTimePicker1.Value.AddDays(2)
Case DayOfWeek.Sunday
DateTimePicker1.Value = DateTimePicker1.Value.AddDays(1)
End Select

MsgBox("You can not select a Saturday or Sunday. The following Monday, " & _
DateTimePicker1.Value.ToShortDateString & ", has been selected.", _
MsgBoxStyle.OKOnly, "Invalid selection")

End If
End Sub