473,379 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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

code green
1,726 Expert 1GB
This question is a follow on from http://bytes.com/topic/net/answers/9...picker-control
I have tried
Expand|Select|Wrap|Line Numbers
  1. DateTime dtStart = DateTime.Now;
  2. 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
Expand|Select|Wrap|Line Numbers
  1. 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
Expand|Select|Wrap|Line Numbers
  1. DateTime dtStart = DateTime.Now;
  2. 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
Dec 7 '10 #1
4 2740
GaryTexmo
1,501 Expert 1GB
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?
Dec 8 '10 #2
code green
1,726 Expert 1GB
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
Expand|Select|Wrap|Line Numbers
  1. DateTime dtStart = DateTime.Now; 
  2. 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
Dec 9 '10 #3
GaryTexmo
1,501 Expert 1GB
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?
Dec 9 '10 #4
code green
1,726 Expert 1GB
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++
Dec 9 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Kingdom | last post by:
I'm using this script to dynamicaly populate 2 dropdowns and dispaly the results. Choose a component type from the first drop down, lets say 'car' and the second box will list all the car...
2
by: Sebastian Meier | last post by:
Hi Everyone, i have a "static" source code which works fine. my problem is now, that the look of the internet page is only to be changed by editing the source code. For better handling of the...
4
by: pbb | last post by:
Is it possible to retrieve VB code stored in SQL Server as text and execute it in code behind in an ASP.Net app? I guess what I'm looking for is an object that would have an Execute method that...
4
by: Antonio | last post by:
hello, I have a data grid being populated from any number of stored procedures. I need to have the totals in the footer, so I use the ItemDataBound event to sum up and display the results. this...
1
by: crabel | last post by:
I have a bunch of expressions stored in the DB that return a boolean value. Is there any way to dynamically parse the DB records so it returns a boolean value at run time? I know I can use the...
3
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
0
by: jobs | last post by:
In the below code, why can't I equate which form to a formview like we do with controls under the main control. The below gives me an error because whichform does not really take all the properties...
3
by: Thomas W | last post by:
Maybe a stupid subject, but this is what I want to do : I got some python code stored in a string: somecode = """ from somemodule import ISomeInterface class Foo(ISomeInterface): param1...
0
by: Chris | last post by:
Hello everyone, I'm trying to do a very simple thing but am having completely no luck. I have a number of articles on my website that I'm migrating into a database table as html (just blog...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.