Solved

C# DateTimePicker set Date

Posted on 2008-10-29
10
2,589 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
Industry Leaders: 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!

 
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

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!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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