locked
How to fetch selected date and value from Calendar RRS feed

  • Question

  • I'm totally new to windows programming and I have a basic questions

    1. Calendar

    Which calendar (datetime picker or monthly calendar)should I use to get the selected date. For instance if a user clicks on a particular date the selected date is returned to a text box. If there is any example I can look at I will really appreciate

    Thanks!!

    Wednesday, October 11, 2006 3:20 PM

Answers

  • You are creating a brand new DateTimePicker instance.  That one will be initialized to today's date.  Change your code to something like this:

    Private Sub dtCalendar_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtCalendar.CloseUp
      Me.txtInquiryDOE.Text = dtCalendar.Value.ToShortDateString
    End Sub

    Thursday, October 19, 2006 1:08 AM

All replies

  • Use the Value property of the DateTimePicker to get the selected date.
    Wednesday, October 11, 2006 11:38 PM
  • Here is the example

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.datetimepicker.value.aspx

     

    Moreover, you may need to handle the CloseUp event which will occur when the user finish selection.

    Thursday, October 12, 2006 8:41 AM
  • Thanks for the replies. I think I'm close but I'm having one problem; it is returning only todays date to the textbox when the users click on any calendar date. Am I doing something wrong here?

     

    Private Sub dtCalendar_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtCalendar.CloseUp

    Dim dP As New DateTimePicker

    MessageBox.Show(dP.Value.ToString())

    Me.txtInquiryDOE.Text = dP.Value.ToShortDateString

    End Sub

     

    Tuesday, October 17, 2006 3:53 PM
  • when I select the date, it does show the selected date on top side of the calendar control but displays todays date on the  textbox and in a messageBox. Basically I just can't seem to pass the user selected date.

    Anyone?

     

    Thanks!

    Wednesday, October 18, 2006 2:10 PM
  • You are creating a brand new DateTimePicker instance.  That one will be initialized to today's date.  Change your code to something like this:

    Private Sub dtCalendar_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtCalendar.CloseUp
      Me.txtInquiryDOE.Text = dtCalendar.Value.ToShortDateString
    End Sub

    Thursday, October 19, 2006 1:08 AM
  • Excellent!

    Thanks for all the help guys!!

    Thursday, October 19, 2006 6:16 PM