I have been using the Windows DateTimePicker to display a time only and allow the user to spin the time.
The key is to just have a line like ctrl.CustomFormat = "HH:mm". The only problem with this is that I have to have a time present in the control at startup. I'd prefer to have it blank until the user starts hitting the up/down buttons.
Can I use the UltraDateTimeEditor for this purpose? I would think so, I have already started the process. I am using a FormatString of hh:mm and a MaskInput of {time}. The Value, I leave blank. I have set the spin button style to "Always". All picked on designer. However, I have a few minor issues:
1. Can I get rid of the dropdown button? I don't need it.
2. The spinning doesn't work quite like the DateTimePicker. When you spin to 12 (on the hours for example) it stops rather than cyle to 1. Is there a way to duplicate the behaviro
3. With the Value not set, it displays as blank. That's fine (and exactly what I want!), but when you hit the spin button, only the hours part comes up. Then you have to do hours minutes and am/pm. It would be nicer if the first time the spin button was hit, it went straight to some time (like 08:00 AM). Can I do this?
4. When you're not editing the control, it doesn't display the AM or PM. I assume the formatstring can be modified to show this?
Thanks,
Andrew
1. Set DropDownButtonDisplayStyle to 'Never'
2. Set SpinWrap to true
3. Not intrinsically; the only solution I can think of would be to maintain an external variable that tracks whether the button has ever been clicked.
4. You used the uppercase "H", which denotes 24-hour time; if you use the lowercase "h", it will display as 12-hour time, and then you use the "t" format specifier to make the AM/PM appear. See here for MSDN documentation on format specifiers.
Brian,
Thanks for all the help. I think I'm very close right now. For #3, I did something slightly different. I hooked into the control Enter event and have:
private void dtpCustom6_Enter(object sender, EventArgs e)
{
if (dtpCustom6.Value == null)
DateTime dt1 = new DateTime(2000, 1, 1, 8, 30, 0);
dtpCustom6.Value = dt1;
}
The only improvement here is that I'd (possibly) like to set the value when the up/down spinner if first clicked. What's the event for that? I tried EditorSpinButtonClick, but that doesn't seem to be the one.
Also, I set SpinWrap to true. It behave slightly differently than the Windows control, which is a problem because users are accustomed to that. Withe the DateTimePicker, if you spin through the hours and get to 11 a.m. and then 12, it will change the AM to PM. The infragistics one should do this too. I'm guessing there's an easy way. As a last resort, if you supply the event that is fired when the spin buttons are clicked, I guess I could hook into that and see if it's the hours that are spinning and take action appropriately. Is there a spin event and does it say if the hours (versus minutes, etc) are spinning?