Home » U++ Library support » CalendarCtrl » switch date format
switch date format [message #24246] |
Thu, 07 January 2010 11:12 |
sapiency
Messages: 56 Registered: September 2008
|
Member |
|
|
Hi,
I'm just playing around with DropDate ...
setting output with:
SetDateFormat("%2:02d/%3:02d/%1:4d");
SetDateScan("mdy");
works fine, but when I switch to "dmy" and open the calendar, it gets the date from the string and use "d" as "m" and "m" as "d" ...
is there allready a way to solve this?
regards
reinhard
|
|
|
|
Re: switch date format [message #24261 is a reply to message #24257] |
Thu, 07 January 2010 20:14 |
sapiency
Messages: 56 Registered: September 2008
|
Member |
|
|
Hi,
I tried AutoFormat(true) and AutoFormat(false), but in both cases I got the wrong result ...
what I did:
- open gui
- click on arrow (calender opens)
- click on current day
- switch output and scan format (output - string is still the same)
- click on arrow and view calender (wrong date)
- switch output and scan format to old style (output - string is still the same)
- click on arrow and view calender (correct date)
I use the following lines to switch:
if( ... )
{
SetDateScan("mdy");
SetLanguage( LNG_( 'E', 'N', 'G', 'B' ) );
SetDateFormat("%2:02d/%3:02d/%1:4d");
}
else
{
SetDateScan("dmy");
SetLanguage( LNG_( 'D', 'E', 'D', 'E' ) );
SetDateFormat("%3:02d/%2:02d/%1:4d");
}
I think this problem could be solved if all Controls derived from Date, receive a Signal that the Strings have been changed.
reinhard
|
|
|
Re: switch date format [message #24266 is a reply to message #24261] |
Fri, 08 January 2010 10:29 |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
Ah, I see. I was confused by your initial post.
There isn't really any mechanism for the sort of singnal you're proposing, but there is another solution:
void CtrlLibTest::SetFormat()
{
static bool toggle = false;
Backup();
if(toggle)
{
SetDateScan("mdy");
SetLanguage( LNG_( 'E', 'N', 'G', 'B' ) );
SetDateFormat("%2:02d/%3:02d/%1:4d");
}
else
{
SetDateScan("dmy");
SetLanguage( LNG_( 'D', 'E', 'D', 'E' ) );
SetDateFormat("%3:02d/%2:02d/%1:4d");
}
Restore();
toggle = !toggle;
}
- Backup serializes the values from the EditFields on the window
- the date format is changed
- Serialize again to restore the data
This makes the EditField re-format it's value and you get the correct result.
In practice you probably don't want to use Backup and Restore as this may interfere with other functions (like cancelling), but what they do is very simple and easy to reproduce. It's only using StringStreams.
If you want to apply this effect globally you could iterate through all the windows using GetTopWindows, or send your own signal to tell windows to do it themselves.
If you really want to send a signal straight to the DateTimeCtrl you'd have to make a derived class and send your own signal.
|
|
|
Goto Forum:
Current Time: Fri Apr 26 05:16:15 CEST 2024
Total time taken to generate the page: 0.03865 seconds
|