Skip to main content
Home Forums Silverlight Programming WCF RIA Services Date Picker default date issue
17 replies. Latest Post by dabooj80 on November 6, 2009.
(0)
dabooj80
Member
9 points
81 Posts
11-03-2009 6:32 AM |
Hi,
I've created a dataform with a couple of datepicker controls for the date fields. I have set this up to be an add new record form so the user can add in details and save a record. But when i run the application and open the page (as a silverlight child window), the default values for the datepicker is 01/01/0001. Also, when i select the calendar icon, i get the calendar starting from Jan 0001.
I have tried to set the IsTodayHighlighted property to true & i've tried to set a value for the DiplayDateStart but i still get the default value stated above. The code for the control is as follows:
The timefixer resource simply converts the date to UK format & to short format. This works and so does the record save when i add in a more recent date value (save falls if i leave the default date values in).
How can i set this so the default value is a more recent date? Also, how can i restrict the date range available when you select the calendar icon?
Ardman
Contributor
3434 points
946 Posts
11-03-2009 7:27 AM |
Have you tried setting the DisplayDateStart and DisplayDateEnd range?
11-03-2009 7:53 AM |
Yep, tried that buut still no luck. i used the following values:
DisplayDateStart="01/01/2000" DisplayDateEnd="11/03/2009"
11-03-2009 8:06 AM |
In your Constructor, try:
dp.DisplayDate =
11-03-2009 9:10 AM |
Hi Ardman,
That sounded like a good solution to me but when i implemented it the dp returned null so brought an error up. I'm assuming that the findname function isnt finding the EpisodeStartDate control. This is what i did:
{
InitializeComponent();
SusDetailsForm2.CurrentItem = newsuslog;
SusDetailsForm2.BeginEdit();
}
11-03-2009 9:13 AM |
If you add a ContentLoaded event handler, then move the DatePicker into there. This should then be available for the code to pick up the details.
11-03-2009 11:01 AM |
Hi Ardman, I know what you mean by "add in a ContentLoaded handler" but i don't know the exact syntax to set it up.
As you might well have gathered, i'm a complete novice at C# & Silverlight development so i struggle with the simplelest of tasks. My apologies for being so poor at this but could you show me how to set up the event handler & where i need to place it?
I don't expect others to do everything for me and i did have a go myself but my code doesn't seem to work:
11-03-2009 12:38 PM |
You just need to add in your Constructor:
this.ContentLoaded += new EventHandler(this.AddNewRec_ContentLoaded);
11-04-2009 10:22 AM |
Sorry mate, i'm still having no luck with this date picker default date selection. I tried your code but i get an error stating: Error 2 No overload for 'AddNewRec_ContentLoaded' matches delegate 'System.EventHandler' C:\Documents and Settings\ahmadshu\My Documents\Visual Studio 2008\Projects\SusExportLog\SusExportLog\Views\AddNewRec.xaml.cs 30 35 SusExportLog
The code i used is as follows (i also tried this._contentLoaded = ... but got the same error):
11-04-2009 11:11 AM |
ok, i tried to look the issue up and changed my code around a bit but now i get a different error:
Error 1 Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<System.Windows.Controls.DataFormContentLoadEventArgs>' C:\Documents and Settings\ahmadshu\My Documents\Visual Studio 2008\Projects\SusExportLog\SusExportLog\Views\AddNewRec.xaml.cs 29 46 SusExportLog
The new code is as follows:
Any ideas on why it is doing that?
Regards, Shuja
11-04-2009 11:35 AM |
In your SusDetailsForm2_ContentLoaded change EventArgs to DataFormContentLoadEventArgs
DataFormContentLoadEventArgs
11-05-2009 8:07 AM |
Ok, i've managed to get the contentLoaded event setup BUT the findname function is still not finding the date picker control. It returns a null value. My control is in a child window, within a grid, within a dataform (called SusDetailsForm2) but the code is still not finding it. Any ideas on how to find the date picker control? Here is my code:
ColinBlair
6741 points
1,318 Posts
11-05-2009 10:44 AM |
The SelectedDate is bound to the EpisodeStartDate. The DatePicker is simply displaying the value that it is bound to. The correct place to default the EpisodeStartDate would be in the entity itself.
11-05-2009 12:17 PM |
Thanks ColinBlair, That makes sense. I have set the default dates for my required fields winthin the entity and this works fine.
BUT I have a date field which is not required by default and so i need to set the DisplayDateStart property to a recent date. I cannot do this in the xaml and when i try to find the date picker control in the code by name it just simply does not find it.
How can i set the DisplayDateStart to a date value in the code? My code now is as follows and i want to set the DateSentToSus date picker control display date start property to the more recent value (instead of the default 01 Jan 0001):
newsuslog.EpisodeEndDate =
dp.DisplayDateStart =
11-05-2009 12:49 PM |
http://forums.silverlight.net/forums/p/132085/295080.aspx
11-05-2009 7:24 PM |
I don't want a default date selected in the DateSentToSus field. This is meant to be blank until the users have an actual date confirmed. What i needed was the range that the display dates showed to be a more recent date than 01 jan 0001.
I.e. if i create a new record the DateSentToSus can be blank & added later in the edit section. BUT i can create a record which has a DateSentToSus date value confirmed so i can insert that date but when i click o the date picker control i hav to start from 01 jan 0001 when i want the calendar to display this month's date's.
The code in your link seems to be a default display date setting. I don't want a default value, just to have a specified date range in the date picker selection.
Any ideas?
11-06-2009 7:04 AM |
If i can find the date picker control through code then i would be able to set the date diplay range values but the .FindName funtion cannot seem to pick up the date picker control. I decided to test this and see what ic can pick up and it turn out that if i give the dataform's datatemplate a name (x:name) then the findname will find this. If i tried to find the cancel button by name, the findname will find that too.
BUT my date picker control is within the data template, within the Edit template, within a root stack panel & then within another stack panel whcih splits the dat into 2 columns. so it is nested within a few things.
But if i try to name any of the stack panels, the findname DOES NOT find these and the control is within the data template within 2 stack panels. I'm assuming that this is the reason i can't find the control. I tried finding the datatemplate & then finding the control through this but the datatemplate does not have a FindName funstion under it.
Can anyone help me find the date picker control through code?
11-06-2009 10:59 AM |
Right, i have managed to stimble on to some sort of solution. I had defined a Binding for the DispayDate as well as the SelectedItem and this was causing the date picker to default the range to start from year 0001. However, when i removed the displaydate from the combox xaml, the date picker calendar showed the current month & today's date was highlighted.
I also removed the displaydate from my editting form and this worked too. When there is an existing value in the date field it displays correctly and when you select the date picker calendar it shows the current month. When there is no date specified then the date picker calendar still displays the current month.
This leads me to ask what is the DisplayDate property used for & what's its point? It seems the selecteditem property does the bindings and the calendar range is defaulted by setting the IsTodayHighlighted so what purpose does the DisplayDate property serve?