views:

383

answers:

1

I'm trying to determine the currently selected portion of the date (or time) editor. I need to to provide custom action when the navigation keys on PDA are use. In particular i want the focus to go to the next control when pressing Right button and having the last portion of the date selected (e.g year). Default behavior is cycling through date portions.

I've looked at Win32 API options for DateTimePicker (link) but it does not seem to support this.

Any suggestions?

A: 

The .Net cf date picker is a PITA.

Have you tried trapping and overriding the KeyUp event for the "Right" button when the focus is on the date picker? You could count the number of times the "Right" key was pressed and in this way you can fake a position setting: Set a counter variable to 1 when the date picker receives focus and increment by one when you intercept the "Right" key. Test to see if it is the "Right" key and if the counter variable is a multiple of three set e.Handled = true to keep the default behavior from executing. Of course your override logic would be to set the focus to the next control.

Edit: Don't forget get to decrement the counter var on "Left" key press!

Custom Option: i think your best bet is to build your own custom date control. i've done this. It's not too difficult. It's a matter of aligning three text boxes in a control and doing some basic validation. You also still use the calendar portion of the picker if you needed to.

It's also worth it to root around in OpenNetCF. There's a ton of classes in it though i'm not sure if there will be an alternative to a date picker. Still, if you do serious CF dev, it's worth a look.

Paul Sasik
Is there any free alternative for the CF.NET DateTimePicker?I'll keep in mind your suggestion. Of course it will not work properly if a combination of keys and stylus is used.
Muxa
i found one free date picker and it was even worse. Honestly i think your best bet is to build your own custom date control. i've done this. It's not too difficult. It's a matter of aligning three text boxes in a control and doing some basic validation.
Paul Sasik