0
votes

There are several QAs here about formatting C# DateTimePickers, but none seem to address this aspect:

The default behavior is when the user clicks the DateTimePicker dropdown he starts at the one-month view, with a scroll bar on top to page through one month at a time.

From the UI, you can move up to year level, but my operators are not local or intuitive with control use. I'm requesting that the user enter data that spans 10 years (date of manufacture for some product). I want to start at the year level to make it faster/easier to start near the right arbitrary place.

Can I make the calendar pulldown automatically start at year level and drill down?

Thanks.

1
The awnser is Yes they can! Are you using ASP.NET or WPF?Peter
Thanks. I am using a MS Visual studio 2010 Windows form application. I do not know what ASP.NET or WPF mean.KevinMacKay
OK figured out its WPFKevinMacKay

1 Answers

1
votes

If you are using WPF then I presume you are referring to the DatePicker control.

In your XAML:

<DatePicker CalendarOpened="DatePicker_CalendarOpened" />

and then in the code behind

using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

private void DatePicker_CalendarOpened(object sender, RoutedEventArgs e)
{
    DatePicker datepicker = (DatePicker)sender;
    Popup popup = (Popup)datepicker.Template.FindName("PART_Popup", datepicker);
    Calendar cal = (Calendar)popup.Child;
    cal.DisplayMode = CalendarMode.Year;
}