Solved

Example to use DTPicker control to display 2 dates

Posted on 2006-11-28
4
315 Views
Last Modified: 2012-05-05
I would like to calculate begindate and enddate using the DTPicker conteol in VB.Net.
Can someonw show an example how to build it?
0
Comment
Question by:zachvaldez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:Hillwaaa
Hillwaaa earned 100 total points
ID: 18034642
Hi zachvaldez,

Can you use two dtpickers?  If so just do:
   Dim start_date As Date
   Dim end_date as Date

 
    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        start_date = Me.DateTimePicker1.Value
    End Sub

    Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged
        end_date = Me.DateTimePicker2.Value
    End Sub

Cheers,
Hillwaaa
0
 

Author Comment

by:zachvaldez
ID: 18035921
I really not sure if this is the best route to go. I plan of putting a date range in two textboxes. But I would like to click an object to display a calendar then select a particular date then that number will entered to a textbox for the begin date . The same is true also in putting an enddate. The result of it . There will be 2 controls showing the begin date and end date.
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 18036401
You just use Hillwaaa's code like this
to calc the number of days.

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        start_date = Me.DateTimePicker1.Value
        TextBox1.Text = start_date.ToString()
    End Sub

    Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged
        end_date = Me.DateTimePicker2.Value
        TextBox2.Text = end_date.ToString()
        TextBox3.Text = (end_date.Date.Subtract(start_date.Date).Days).ToString

    End Sub
0
 
LVL 18

Accepted Solution

by:
vbturbo earned 100 total points
ID: 18037284
And here is how to create a dynamic datepicker

Imports System.Windows.Forms

' Create a new DateTimePicker control and initialize it.
Dim DateTimePicker1 As New DateTimePicker()
Dim DateTimePicker2 As New DateTimePicker()

Dim start_date As Date
Dim end_date as Date

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click    
    ' Set the MinDate and MaxDate.
    DateTimePicker1.MinDate = New DateTime(1969, 11, 29)
    'DateTimePicker1.MaxDate = DateTime.Today
   
    ' Set the CustomFormat string.
    DateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"
    DateTimePicker1.Format = DateTimePickerFormat.Custom
   
    ' Show the CheckBox and display the control as an up-down control.
    DateTimePicker1.ShowCheckBox = True
    DateTimePicker1.ShowUpDown = True

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click    
    ' Set the MinDate and MaxDate.
    DateTimePicker2.MinDate = New DateTime(1969, 11, 29)
    'DateTimePicker2.MaxDate = DateTime.Today
   
    ' Set the CustomFormat string.
    DateTimePicker2.CustomFormat = "MMMM dd, yyyy - dddd"
    DateTimePicker2.Format = DateTimePickerFormat.Custom
   
    ' Show the CheckBox and display the control as an up-down control.
    DateTimePicker2.ShowCheckBox = True
    DateTimePicker2.ShowUpDown = True

End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        start_date = Me.DateTimePicker1.Value
        TextBox1.Text = start_date.ToString()
    End Sub

    Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged
        end_date = Me.DateTimePicker2.Value
        TextBox2.Text = end_date.ToString()
        TextBox3.Text = (end_date.Date.Subtract(start_date.Date).Days).ToString

    End Sub

Is this what you mean ?
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question