Solved

DateTimePicker - setting the default month on DropDown

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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