Link to home
Start Free TrialLog in
Avatar of jamesdean666
jamesdean666

asked on

C# DateTimePicker set Date

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();
            }
        }
ASKER CERTIFIED SOLUTION
Avatar of silemone
silemone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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);
Avatar of jamesdean666
jamesdean666

ASKER

I can't quite get that to work.

Can you please provide the code?  
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?
ok...dropdown calendar...not a dropdownlist...got it...

can i see your code so far on  how you're creating this dropdown so that i can have a better understanding....thanks
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);
and by your Gateway, I assume you mean your Main class and that this is a desktop application?
correct.
Thnx.