Solved

DateTimePicker - setting the default month on DropDown

Posted on 2004-10-06
5
648 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

23 Experts available now in Live!

Get 1:1 Help Now