DateTimePicker dynamic date code is mysteriously replaced by hard-coded date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    DateTimePicker dynamic date code is mysteriously replaced by hard-coded date

    This question is a follow on from http://bytes.com/topic/net/answers/9...picker-control
    I have tried
    Code:
    DateTime dtStart = DateTime.Now;
    this.dtPickStart.Value = dtStart.AddMonths(-1);
    And this seems to work fine.
    But what is totally baffling is, when I open the project the following day,
    the above code has disappeared and been replaced with
    Code:
    this.dtPickStart.Value = new System.DateTime(2010, 11, 6, 10, 12, 2, 547);
    I have doubted whether I actually saved everything properly so double checked, reverted the code back to
    Code:
    DateTime dtStart = DateTime.Now;
    this.dtPickStart.Value = dtStart.AddMonths(-1);
    but the following day it has gone again and been replaced by the hard-coded date.
    This is in Visual Studio 2008 environment.
    Can anybody explain this. Thanks
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Baffling indeed!

    My question for you is, does this happen on the same day if you close down VS and then open it back up and open your project, or is it only when you open it the next day?

    I tried that test in VS 2010 and everything worked as expected, so I'll have to wait until tomorrow to check whether or not the time period has anything to do with it.

    Has that line ever had the hard coded value in it? Is there a source control system involved here? What happens if you put a couple of comments around it, will that revert too?

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      does this happen on the same day if you close down VS and then open it back up and
      It actually hard codes the current date.
      So if I don't re-edit this code it stays the same.
      So currently it has not changed for three days.

      My idea is to have two DatePicker controls.
      One with todays date and the other showing one month ago,
      as this is the most suitable period for the end user.

      But todays date is 2010-12-09 and the DatePicker control is showing 2010-11-06 - the last time I re-inserted the code
      Code:
      DateTime dtStart = DateTime.Now; 
      this.dtPickStart.Value = dtStart.AddMonths(-1);
      OK, a few days is not critical but obviously the gap will widen.

      How does the code get overwritten?
      Has that line ever had the hard coded value in it?
      Yes, originally.
      I then changed it to make the date dynamic.
      I suspect one of the deeper classes in the control is doing this somewhere.

      By the way, I have not tested this with a 'release' version yet to see what happens.
      This problem occurs on two similar forms opened from a menustrip in a MDI project

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        I just checked the version I have... as I suspected, the code I wrote has stayed there. I really can't explain why your code is changing on its own...

        You never mentioned anything about version control... is it possible that's a factor?

        That's all I've got... I wouldn't expect source code to change like that. Oh! Something else to try... maybe the designer is forcing it? Well, that shouldn't change your non designer classes, but maybe it's worth a shot. Delete the datetime picker control, then re-add it. Don't use the designer to set the value, but put your code into your main form's constructor or form load event?

        Comment

        • code green
          Recognized Expert Top Contributor
          • Mar 2007
          • 1726

          #5
          Visual Studio is a wonderful time saver until something like this happens.
          This occurance is impossible when hard-coding in a more simple text editor without the drag and drop facility.
          Oh well, I will try removing, rebuilding then adding the controls again, avoiding any defaults.
          Now where did I put my Notepad++

          Comment

          Working...