populating textbox using datetime picker
I am using VB 2005 for developing a winform application
I want to display a datetime picker ( or a calendar) to choose date when a user click on the textbox
very similar towww.expedia.com
on the textbox click event I am using the following code to display datetime picker's calendar GUI
PrivateSub TextBox1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles TextBox1.ClickDateTimePicker1.Select()
SendKeys.Send(
"%{DOWN}")EndSubis there any easy to remove the combobox out of the Datetime picker? so when a user click on the textbox
datetime picker's calendar Gui will displayed and a user selects a date that populates the textbox
[1791 byte] By [
c_shah] at [2007-12-24]
Hi,
is there some reason why you don't want to use DateTimePicker itself for choosing dates?
Here's also something you can start with:
You have a text box on your form. Put a MonthCalendar on the form and set its Visible property to False.
Write the following handlers:
Private Sub TextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Click
MonthCalendar1.Location = New Point(TextBox1.Left, TextBox1.Bottom)
MonthCalendar1.Show()
End SubThe first one will open the MonthCalendar below the text box when text box gets clicked on.
Private Sub MonthCalendar1_DateSelected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateSelected
TextBox1.Text = e.Start.ToShortDateString()
MonthCalendar1.Hide()
End SubThe second one will enter selected date in the text box and hide the calendar, when a date has been selected.
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = ChrW(Keys.Escape) AndAlso MonthCalendar1.Visible Then
MonthCalendar1.Hide()
e.Handled = True
End If
End SubThe last one will just hide the calendar if escaped was pressed when text box has focus.
Andrej