Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7665793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:40:02+00:00 2026-05-31T14:40:02+00:00

I have a DateTimePicker with ShowCheckBox = true on my winforms app. If I

  • 0

I have a DateTimePicker with ShowCheckBox = true on my winforms app. If I do this in the forms constructor:

        DateFrom.Checked = true;
        DateFrom.Value = DateTime.Today.AddDays(-7);

Then set DateFrom.Checked = false; in the FormShown event, it does what I would like, the text in the control defaults to 7 days before today, and the checkbox is unchecked.

If I try to only set the Value, the text stays as today. If I reset Checked = false anytime before the FormShown event, the text stays as today.

Now I’ve moved this code to a user control, so to use the same “hack” will require even more hacking, so at this point I’m hoping someone has an easier method. Maybe just another property I can set besides from Value that actually works? 🙂

I tried this also:

        DateFrom.Text = DateTime.Today.ToString(DateFrom.CustomFormat);

Instead of setting the value, or in addition to it, to no avail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:40:04+00:00Added an answer on May 31, 2026 at 2:40 pm

    Typical, I tried for hours before posting my question, then right after I thought it might somehow be related to the creation of the window handle. So I came up with this solution. Will still be happy to have something better, but this doesn’t seem to bad if I have to stay with this:

            DateFrom.Checked = true;
            DateFrom.Value = DateTime.Today.AddDays(-7);
            if (DateFrom.Handle == null)
                System.Threading.Thread.Sleep(0);
            DateFrom.Checked = false;
    

    Checking Handle forces the window handle to be created, so then I’m able to uncheck the control without it defaulting to today’s date for the text when the window handle is created later. I just use Sleep(0) as a trick to make sure the compiler doesn’t optimize the code and compile it out all together (not sure if that would even happen, but like to be sure, and condition shouldn’t always be false so should never Sleep(0) anyway).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have calender datetimepicker jquery. when I am calling this in simple aspx page
In my model I have: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = {0:dd/MM/yyyy})] public DateTime StartDate
I have a ComboBox and a DateTimePicker control in a .net forms application. The
I have created this editor template: @model DateTime? @using MyMvcApp.Properties <div id=dateTimePicker_@(ViewData.ModelMetadata.PropertyName)> <script type=text/javascript
I have the following script: $(function() { $( 'input[id^=event_' ).each(function() { this.datetimepicker({ stepMinute: 15
I have a DateTimePicker and it is currently displaying Friday, June 26 2009 How
I need to have a DateTimePicker which will be able to select the Time
I have created the DateTimePicker control. Now i want to add localization Support with
I have to take 2 values from DateTimePicker and then compare their values with
I have a user control which has a DateTimePicker overlaid with the single line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.