views:

193

answers:

1

Currently my DateTimePickers are blank, I would like them to have a default setting i.e

Today.AddYears(20); & Today.AddDays(5);

What I have done at the moment is 'DateTimePicker.Text = DateTime.Today.AddYears(-100).ToString();' As you can probably tell, this isn't working hence why I'm asking the question.

Bit of information :- I need it so that if they arent changed and the button is pressed it uses the default dates. If they are changed, I obviously need to use the changed dates.

Suggestions.

XAML ADDED:

<igEditors:XamDateTimeEditor Name="startDateTimePicker"
  Grid.Row="1"
  Grid.Column="1"
  xmlns:igEditors="http://infragistics.com/Editors"
  Height="18"
  Width="100"
  Format="yyyy-MM-dd"
  VerticalAlignment="Top"
  HorizontalAlignment="Center" />
+2  A: 

Setting the Value property should do the trick:

DateTimePicker.Value = DateTime.Today.AddYears(-100);

And since it's type is DateTime, you don't need any ToString conversions.

Oded
Thanks for this, however this still isn't showing a value in my DTP. Do I perahps have a problem in my XAML? Would it be an idea to make the Value in to a var and in my XAML put 'Text="var"' ? Thanks!
Vibralux
@Vibralux - I assumed winforms, as you did not put any details to the contrary. Can you post the relevant XAML snippet and the code you are using? And provide a link to the DTP you are using.
Oded
Sorry, the application is WPF. Beg your pardon. My XAML for my DTP is as follows: @ Oded, was in the middle of doing that :)Sorry
Vibralux
@Vibralux - can you please edit your question and add the data there?
Oded
@ Oded, any chance you could shed a bit of light on your editing techniques for the forums as well?
Vibralux
@Vibralux - Four spaces before code snippets. Highlight code and click the 0101010 button. For more help, click the orange `?` on the top left of the editor.
Oded
@Oded Thanks - Any answers to my other question :D
Vibralux
@Vibralux - Sorry, I don't know WPF/XAML.
Oded