4
Answers

Calendar help please

Amy Turnbull

Amy Turnbull

17y
2.4k
1
How can I close and validate a calendar?

These are my two calendars that pop-up using a button

the calendar code

        private void cdrCalendarStart_SelectionChanged(object sender, System.EventArgs e)
        {
        {
            //displaying the selected date into a textbox

            tbstartdate.Text = cdrCalendarStart.SelectedDate.ToShortDateString();
            cdrCalendarStart.Visible= false; //hiding the calendar.
        }
        }

        private void cdrCalendarFin_SelectionChanged(object sender, System.EventArgs e)
        {
        {
            //displaying the selected date into textbox

            tbfinishdate.Text = cdrCalendarFin.SelectedDate.ToShortDateString();
            cdrCalendarFin.Visible= false; //hiding the calendar.
        }
        }

the buttons

        private void btstartdate_Click(object sender, System.EventArgs e)
        {
                                               
            /*this sets the date format once date is selected to appear in the textbox */

            try
            {
                if(tbstartdate.Text.Trim() != "")
                    cdrCalendarStart.SelectedDate = Convert.ToDateTime(tbstartdate.Text);
                   
            }
            catch
            {}
            cdrCalendarStart.Visible= true;    //showing the calendar.
       
        }

        private void btfindt_Click(object sender, System.EventArgs e)

        {   /*This sets the date format once date is selected to appear in the textbox */
           
            try
            {
                if(tbfinishdate.Text.Trim() != "")
                    cdrCalendarFin.SelectedDate = Convert.ToDateTime(tbfinishdate.Text);
            }
            catch
            {}
            cdrCalendarFin.Visible= true;  //showing the calendar.
       
        }

I want to be able to have a close option of the calendar and validate the dates, so when the user selects that date and then when it gets to selecting the finish date I need show that the user can only select the days after what was slected in the start date.

Can anyone help?
Answers (4)