Solved

C# DateTimePicker set Date

Posted on 2008-10-29
10
2,571 Views
Last Modified: 2012-05-05
In the code below, I am attempting to set the date that displays in my datetimepicker after I hit the Drop Down arrow.  I would like to displays today's date in the drop down calendar once I click the Drop Down arrow.  The code I am have below is not working.


 private void dtpChangeEffDate_DropDown(object sender, EventArgs e)
        {
            if (this.dtpChangeEffDate.Value.ToShortDateString() != DateTime.Now.ToShortDateString())
            {
               
                this.dtpChangeEffDate.Value = DateTime.Now;
                this.dtpChangeEffDate.Text = DateTime.Now.ToShortDateString();
            }
        }
0
Comment
Question by:jamesdean666
  • 6
  • 4
10 Comments
 
LVL 21

Accepted Solution

by:
silemone earned 500 total points
ID: 22832018
The problem is you have to first:  create a listItem and that item will have...then you have to add the listItem to the dropdownlist...


dr.Items.Add(listItem);
0
 
LVL 21

Expert Comment

by:silemone
ID: 22832028
The problem is you have to first:  create a listItem and that item will have date information...then you have to add the listItem to the dropdownlist...


dr.Items.Add(listItem);
0
 

Author Comment

by:jamesdean666
ID: 22832274
I can't quite get that to work.

Can you please provide the code?  
0
 
LVL 21

Expert Comment

by:silemone
ID: 22832392
What is this event for--->  private void dtpChangeEffDate_DropDown(object sender, EventArgs e)

if it's for a dropdown, then are you trying to add a new select option once it opened?
0
 
LVL 21

Expert Comment

by:silemone
ID: 22832403
ok...dropdown calendar...not a dropdownlist...got it...

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 21

Expert Comment

by:silemone
ID: 22832422
can i see your code so far on  how you're creating this dropdown so that i can have a better understanding....thanks
0
 

Author Comment

by:jamesdean666
ID: 22832670
I derive the value from a call to a method (ChangeEffectiveDate) in my Gateway with the code below:


this.dtpChangeEffDate.Value = this.mGatwy.ChangeEffectiveDate(this.txtPolNumber.Text.ToUpper(), pEffDate);
0
 
LVL 21

Expert Comment

by:silemone
ID: 22833110
and by your Gateway, I assume you mean your Main class and that this is a desktop application?
0
 

Author Comment

by:jamesdean666
ID: 22833149
correct.
0
 

Author Closing Comment

by:jamesdean666
ID: 31511206
Thnx.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

10 Experts available now in Live!

Get 1:1 Help Now