none
Setting DateTimePicker Default Value

    Question

  • hi everyone i have a problem on setting the default value of my date time picker. i have created this application 

    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
           
            Me.EventDataTableAdapter.Fill(Me.EventDataDataSet2.EventData)
            Dim m1 As MsgBoxResult
            t = calendar.SelectionRange.Start.Month.ToString & calendar.SelectionRange.Start.Day.ToString
    
            If Date.Today = calendar.TodayDate And File.Exists(t) = True Then
                m1 = MsgBox("You have events set for today. Would you like to view them?", MsgBoxStyle.YesNo)
    
                If m1 = MsgBoxResult.Yes Then
                    add.Show()
                    Me.Hide()
    
                End If
    
    
            End If
        End Sub

    Private Sub calendar_DateSelected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles calendar.DateSelected
            t = calendar.SelectionRange.Start.Month.ToString & calendar.SelectionRange.Start.Day.ToString
    
            Try
    
                If File.Exists(t) = True Then
                    add.Show()
                    Me.Hide()
    
                Else
    
                    m = MsgBox("Would you like to enter events for this date?", MsgBoxStyle.YesNo)
                    If m = MsgBoxResult.Yes Then
                        add.Show()
                        Me.Hide()
    
                    End If
                End If
    
            Catch ex As Exception
                MsgBox(ex.Message)
    
            End Try
        End Sub

    when u clicked on the date this form will come out

    and my problem is i want to set the default value of my DateTimePicker(dtpDate) depending on which date was clicked on the calendar in Main Form.

    can anyone help me? i've been posting this program of mine this past few days now. i just really need to finish this for my upcoming thesis defense.



    • Edited by Jhude Wednesday, February 15, 2012 2:28 PM
    Wednesday, February 15, 2012 2:01 PM

Answers

  • Hi,

    You can read or write that is GET or SET the DATE of a DateTimePicker like this.>>

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            My.Application.ChangeCulture("en-Us")
            My.Application.ChangeUICulture("en-Us")
            dtpFrom.Value = Convert.ToDateTime("02/15/2012 12:00AM")
            dtpTo.Value = Convert.ToDateTime("02/15/2012 12:00AM")
    
        End Sub

    Just to show what Amit Goval is saying above try this.>>

    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            My.Application.ChangeCulture("en-Us")
            My.Application.ChangeUICulture("en-Us")
    
        End Sub
    
        Private Sub dtpDate_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpDate.ValueChanged
    
            dtpFrom.Value = Convert.ToDateTime(dtpDate.Value.ToLongDateString & " 12:00AM")
            dtpTo.Value = Convert.ToDateTime(dtpDate.Value.ToLongDateString & " 12:00AM")
    
        End Sub
    
    End Class





    Regards,

    profile for John Anthony Oliver at Stack Overflow, Q&A for professional and enthusiast programmers

    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    App Hub for Windows Phone & XBOX 360 developers.



    • Edited by John Anthony Oliver Wednesday, February 15, 2012 2:27 PM
    • Marked as answer by Jhude Thursday, February 16, 2012 7:28 AM
    • Unmarked as answer by Jhude Thursday, February 16, 2012 10:38 AM
    • Marked as answer by Jhude Thursday, February 16, 2012 10:38 AM
    Wednesday, February 15, 2012 2:18 PM

All replies