Solved

DateTimePicker - setting the default month on DropDown

Posted on 2004-10-06
5
654 Views
Last Modified: 2012-08-13
WinForms application in VB.Net...

I have a DateTimePicker in my application.  When the user drops down the dtp to reveal the calendar, I want to somehow set the default calendar month to the current month - irrespective of the current value of the dtp.

I want to do this without actually changing the dtp's value.  In other words, after dropping down the dtp, if the user decides not to change the date and clicks off the dtp without selecting another date then I want the date to remain the same as before the dtp was dropped down.

I hope that makes sense.

Thanks
0
Comment
Question by:Sigh_Man
  • 3
5 Comments
 
LVL 1

Author Comment

by:Sigh_Man
ID: 12236792
To clarify...

if the current date value is 1 January 2000, I still want the dtp calendar to show (by default) this month, ie October 2004 on DropDown.
0
 
LVL 19

Assisted Solution

by:Desp
Desp earned 20 total points
ID: 12236937
Dim d As DateTime = DateTimePicker1.Value
DateTimePicker1.Value = Now.Month.ToString() + "-" + d.Day.ToString() + "-" + d.Year.ToString()
0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 12237039
I don't want to change the value - I just want the drop down calendar to display THIS MONTH rather than the month of the dtp's current value.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 80 total points
ID: 12238795
I don't think it can be done without changing the current value.  Here is a way to store the current value and then put it back if the user clicks off the DTP without changing the value.  If you dismiss the dropdown with the ESC key though, that registers as a change so it doesn't work then.

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private dtpValue As DateTime
    Private dtpChanged As Boolean

    Private Sub DateTimePicker1_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.DropDown
        dtpValue = DateTimePicker1.Value
        DateTimePicker1.Value = Now
        dtpChanged = False
    End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        dtpChanged = True
    End Sub

    Private Sub DateTimePicker1_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.CloseUp
        If Not dtpChanged Then
            DateTimePicker1.Value = dtpValue
        End If
    End Sub

End Class
0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 12242665
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tabcontrol Caption? 1 31
Create XML 5 47
VB.NET HttpWebRequest 12 58
Visual Studio .Net 2012 and Crystal Reports 9 49
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now