Please help me solve this problem

zy_abc

Regular
Joined
May 2, 2003
Messages
67
Visual Basic:
 Private Sub MonthCalendar1_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateSelected
        If MonthCalendar1.SelectionStart > MonthCalendar1.TodayDate Then
            MsgBox("Date cannot be greater than today date")
            MonthCalendar1.Visible = True
            MonthCalendar1.Focus()
        Else
            MonthCalendar1.Visible = False
            per_dob.Text = MonthCalendar1.SelectionStart
        End If
    End Sub

    Private Sub MonthCalendar1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MonthCalendar1.Leave
        If MonthCalendar1.Visible = True Then
            MsgBox("Please close the calendar")
        End If
    End Sub

In the above code when i select the date i make the monthcalendar visible=false. Still i get the msg "Please close the calendar" when the date is selected. Could anyone please tell me where i have gone wrong. I get the msgbox displayed sometimes. How to avoid that.
 
The problem seems to be that setting the MonthCalendar1.visible = false causes the MonthCalendar1_Leave event to be fired, how are you using this calendar (as a pop-up windows or as part of a form?)
 
Thks for the reply. It is a part of the form. When a button is clicked the monthcalendar is made is visible. If the date selected is correct i want to hide the monthcalendar. if the user opens the monthcalendar and tries to fill the other details i want to tell him to select the date and close the calendar.

How can it be acheived? Please help me out
 
But if we use DateTimePicker Time will get displayed. Further this calender is for Date of Birth. Is DateTimePicker suitable for this?
 
Back
Top