Question Datetimepicker pop-up calendar does not disappearing automatically

kashfia

New member
Joined
Oct 27, 2010
Messages
1
Programming Experience
Beginner
Hi,

I am using datetimepicker control.

Initially I am setting

DateTimePicker1.CustomFormat = " "

DateTimePicker1.Format = DateTimePickerFormat.Custom

then it showing a blank control.

Then when I want to select a date from pop-up calender I am using the following code at valuechanged event.

Public Class Form1

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged


DateTimePicker1.CustomFormat = "yyyyMMdd"
DateTimePicker1.Format = DateTimePickerFormat.Short

End Sub
End Class

But the problem is the pop-up calendar does not disappearing automatically. I have to click the mouse outside. then it disappears and the date is shown in the control.

Can anyone help me on this issue.

thanks

Kashfia
 
I don't have VS 2005 installed but I just tried on VS 2008 targeting .NET 2.0 and it worked fine for me. I set the Format to Custom and the CustomFormat to " " in the designer, then I just did this:
VB.NET:
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
    Me.DateTimePicker1.Format = DateTimePickerFormat.Short
End Sub
There's no point setting the CustomFormat to anything else if you're changing the Format, because CustomFormat is only relevant when Format is Custom.
 
Back
Top