Solved

C# DateTimePicker set Date

Posted on 2008-10-29
10
2,578 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

778 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