Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. the bug of datetimepicker control?

the bug of datetimepicker control?

Scheduled Pinned Locked Moved C#
helpcsharptutorialquestionworkspace
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bright Zhang
    wrote on last edited by
    #1

    Environment: vs2003.net winform,windows application Form1: components: - datetimePicker1 - button1 - toolbar1 - toolbarButton1 events: button1_onclick(object sender,EventAgs e) { MessageBox.Show(datetimePicker1.Value.ToString("yyyy-MM-dd")); } toolbar_onclick(...) { if(e.Button == toolbarButton1) MessageBox.Show(datetimePicker1.Value.ToString("yyyy-MM-dd")); } test: suppose the original value of the datetimepicker is:2006-10-12 and now enter a number 11 into the month-part of the datetimepicker,then click button1,a messagebox shows:2006-11-12,not 2006-10-12. and follow the step,enter another number:9 into the month-part of the datetimepicker,and click toolbarButton1,a messagebox shows a value also,however it's not 2006-09-12(normally it should be this),it's 2006-11-12. for this,I conclude that datetimepicker's value is not synchronous with the mannual input from keyboard,after it's not out of focus,then value will be updated.after input,for button1,when I click it,it will occur that datetimepicker will be out of focus,however toolbarbutton1 not.so this is the difference between button and toolbarbutton,and the difference leads to a wrong value when getting datetimepicker's value in both events. and who can tell me how to resove the problem? much thanx~

    S 1 Reply Last reply
    0
    • B Bright Zhang

      Environment: vs2003.net winform,windows application Form1: components: - datetimePicker1 - button1 - toolbar1 - toolbarButton1 events: button1_onclick(object sender,EventAgs e) { MessageBox.Show(datetimePicker1.Value.ToString("yyyy-MM-dd")); } toolbar_onclick(...) { if(e.Button == toolbarButton1) MessageBox.Show(datetimePicker1.Value.ToString("yyyy-MM-dd")); } test: suppose the original value of the datetimepicker is:2006-10-12 and now enter a number 11 into the month-part of the datetimepicker,then click button1,a messagebox shows:2006-11-12,not 2006-10-12. and follow the step,enter another number:9 into the month-part of the datetimepicker,and click toolbarButton1,a messagebox shows a value also,however it's not 2006-09-12(normally it should be this),it's 2006-11-12. for this,I conclude that datetimepicker's value is not synchronous with the mannual input from keyboard,after it's not out of focus,then value will be updated.after input,for button1,when I click it,it will occur that datetimepicker will be out of focus,however toolbarbutton1 not.so this is the difference between button and toolbarbutton,and the difference leads to a wrong value when getting datetimepicker's value in both events. and who can tell me how to resove the problem? much thanx~

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Maybe the following helps you out. At least it gets rid of duplicate code.

      toolbar_onclick(...)
      {
      if(e.Button == toolbarButton1)
      button1.PerformClick();
      }


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      B 1 Reply Last reply
      0
      • S Stefan Troschuetz

        Maybe the following helps you out. At least it gets rid of duplicate code.

        toolbar_onclick(...)
        {
        if(e.Button == toolbarButton1)
        button1.PerformClick();
        }


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        B Offline
        B Offline
        Bright Zhang
        wrote on last edited by
        #3

        adding some buttons can resove the problem,but it seems awkward and duplicate. thank you very much anyway.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups