Solved

DateTimePicker - setting the default month on DropDown

Posted on 2004-10-06
5
687 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
[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
  • 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 86

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

623 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