question about retrieve single selected date in MonthCalendar

hi, i am new to c#, in my project, when a date on the monthcalendar is selected, i want to catch the date for future use (e.g. retrieve all the bookings on that date from db).

i have read some articles about this, now i can call "SelectionRange.start.ToString(); " to get the starting date and call "SelectionRange.end.ToString(); " to get the ending date.

what about a single date selected i tried "SelectionRange.start.ToString(); " and "SelectionRange.end.ToString(); " both work fine. I am just wondering if there is something specifically for a single date selection




Answer this question

question about retrieve single selected date in MonthCalendar

  • rooz

    I'd say that your hint is not very helpful, sorry JohnAskew

    I tried this: txt1.Text = MonthCalendar1.DateSelected.ToString();

    it gave me error: "'System.Windows.Forms.MonthCalendar.DateSelected' can only appear on left hand side of += or -="

    dont get it, plz help



  • caprio

    MonthCalendar online help

    It appears that what you've found is an event handler whose "DateRangeEventArgs" holds the selected date in it.


        private void monthCalendar1_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e)
        {
            // Show the start and end dates in the text box.
            this.textBox1.Text = "Date Selected: Start = " +
                e.Start.ToShortDateString() + " : End = " + e.End.ToShortDateString();
        }

        private void monthCalendar1_DateChanged(object sender, System.Windows.Forms.DateRangeEventArgs e)
        {
            // Show the start and end dates in the text box.
            this.textBox1.Text = "Date Changed: Start =  " +
                e.Start.ToShortDateString() + " : End = " + e.End.ToShortDateString();
        }


  • Charles Gray

    Look for a different property on the MonthCalendar that stores this data.

    Perhaps a property called "date", e.g.   myMonthCalendar.date  to get or set the data.

     


  • theManMyth

    Just set the MaxSelectionCount to 1 so that users cannot select more than one day. Then in the SelectedRange.start.ToString(). There is nothing available to show the selection of only one day.


  • rhallet

    thx Justin for your advice, the setting is exactly what i did, and it works fine, maybe the single date selection method will be available in .net2007

  • question about retrieve single selected date in MonthCalendar