Results 1 to 3 of 3

Thread: Need to create a datepicker conrol with checkboxes for each date

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    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

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  3. #3

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    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:

    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
    Last edited by Nitesh; Dec 8th, 2009 at 01:13 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width