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
Solved

C# DateTimePicker set Date

Posted on 2008-10-29
10
2,582 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

790 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