Need to create a datepicker conrol with checkboxes for each date
Hi Guys,
I need to define weeks for my app. So I want to select a certain week of a month. then I want to tick the days that apply and save those dates to a table. Please advise me on how to do this. I would really appreciate it
Re: Need to create a datepicker conrol with checkboxes for each date
What about using a monthcalendar control? This control allows a date range to be selected. With a little bit of code, you can ensure that when the user selects any date, that the entire week is selected.
Plop a MonthCalendar control on a form, and put this code in:
Code:
Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
MonthCalendar1.SelectionStart = e.Start.AddDays(-e.Start.DayOfWeek)
MonthCalendar1.SelectionEnd = MonthCalendar1.SelectionStart.AddDays(6)
End Sub
it works pretty well ;)
Re: Need to create a datepicker conrol with checkboxes for each date
thanks kleinma. this is very handy;). reading up on this control a bit after testing, because it behaves quite weirdly when making a range selection and scrolling back a month or two and I found this on msdn:
Quote:
Scrolling through the calendar display with the navigation buttons when a range is selected can cause unexpected results (for example, the date range is not preserved). If you have a single month displayed with a range of 04/01/2001 to 04/10/2001, scrolling the calendar to March changes the selected range as follows: 03/01/2001 to 03/10/2001. If you have multiple months displayed, such as March and April with a selected range of 04/01/2001 to 04/10/2001, scrolling the calendar back to January and February changes the selected range as follows: 01/01/2001 to 01/10/2001.
Note:
Setting the SelectionRange for a MonthCalendar control that has visual styles enabled will result in the selection range not painting correctly on the control.
sometimes it statys stuck on a certain month. so if I scroll back to July, select a day, (which then highlights the days in that week) and then try to scroll forward to september, it is stuck on july
I like your method alot, but this issue is a problem for me:(