Answered Setting DateTimePicker Default Value

  • Wednesday, February 15, 2012 2:01 PM
     
      Has Code

    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
    •  

All Replies

  • Wednesday, February 15, 2012 2:13 PM
     
     Proposed

    Use dtpDate ValueChanged event to set the value for other two DTP Control.

    To set default value, you can use

    dtpdate.Value = now.date()


    Amit Govil | Email

    "Weeks of coding can save you hours of planning"

  • Wednesday, February 15, 2012 2:18 PM
     
     Answered Has Code

    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:23 PM
     
     

    wow! thank you very much sir!

  • Wednesday, February 15, 2012 2:36 PM
     
     

    wow! thank you very much sir!

    Hi,

    You are welcome, and welcome to the Microsoft forums.  :)

    Please mark the post(s) and replies in this thread as helpful or / and

     as answer by clicking on the appropriate green triangles and links.

    Please also do the same for any future question(s) you may have.

    Remember, only do this for those posts you feel fully ( or even partially ) answer your question(s).




    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.

  • Thursday, February 16, 2012 9:36 AM
     
     

    aye aye sir!

    and thank you again =)

  • Thursday, February 16, 2012 10:24 AM
     
     

    sir John Anthony Oliver

    another question do you know how to filter the datagrid view? im thinking of, the data that will only show in the datagridview depends on the date selected on the dtpDate.

    example if the value of Date is march 20 2012 the data that will only show on the datagrid view is the event that is save on the march 20 2012. also to arrange it ascending based on time start. thank you and sorry for the trouble =)


  • Thursday, February 16, 2012 4:19 PM
     
     

    sir John Anthony Oliver

    another question do you know how to filter the datagrid view? im thinking of, the data that will only show in the datagridview depends on the date selected on the dtpDate.

    example if the value of Date is march 20 2012 the data that will only show on the datagrid view is the event that is save on the march 20 2012. also to arrange it ascending based on time start. thank you and sorry for the trouble =)


    Hi,

    Can you please click on this.>>

    ASK A QUESTION IN THE FORUMS

    for this new question?

     Please also mention whether you are doing this with a database and what type of database file you are connecting with.




    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.

  • Friday, February 17, 2012 12:43 AM
     
     
    oh i see. ok sir.