Solved

C# DateTimePicker set Date

Posted on 2008-10-29
10
2,586 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
[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
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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