[RESOLVED] [02/03] Datetimepicker stores location on leave?
Hi,
I don't know if anyone else has ever come across this, using VS2003 whenever you leave a datetimepicker, it stays where it was before. For example when typing in 03/30/06, if you leave on 06, it will focus on 06 when I reenter the control. Is there a way to reset the focus back to the 03 (month)? Thanks!
Re: Datetimepicker stores location on leave?
This is the default action of the dtp. You could probably send a keypress to the dtp to left arrow twice.
Re: Datetimepicker stores location on leave?
you could set the value in the datetimepickers enter event
Code:
Private Sub DateTimePicker1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.Enter
DateTimePicker1.Value = "01/03/2006"
End Sub
i dont see much point in reseting the date every time you reopen the control though
Re: Datetimepicker stores location on leave?
Hes interested in setting the focus to the month part and not setting its value. ;)
Re: [02/03] Datetimepicker stores location on leave?
ahh, i realy should read things properly
Re: [02/03] Datetimepicker stores location on leave?
It's the default behaviour of every control to maintain the current selection when it loses focus. Try selecting part of the text in a TextBox, then press tab until the same TextBox receives focus again. You'll see that the same text is still selected. There is no way to programmatically get or set what part of the text is selected in a DTP as far as I can see. You could use Rob's suggestion but there is no guarantee that the year is what's selected so you may actually remove the selection from the day rather than set it.
Re: Datetimepicker stores location on leave?
Quote:
Originally Posted by RobDog888
This is the default action of the dtp. You could probably send a keypress to the dtp to left arrow twice.
Is there a way to determine which portion of the DTP the user is on right now? What if only the day changes, so the user leaves at 30 when the date is 03/30/06? What if the values are the same 03/03/03 (so, I can't compare any values)?
Yup, I'm just trying to reset the focus back to the month portion. Someone told me that I should just dispose and recreate it, I thought they might be some function I was missing.
Someone told me that I could dispose/recreate the control, but that doesn't seem like a sound way of doing things (unless it's necessary).
Re: [02/03] Datetimepicker stores location on leave?
Well if your on the day part and you send two left arrow keypresses it will be back on the year part. So maybe disposing and recreating it may be the easiest and sure fire method.
Re: [RESOLVED] [02/03] Datetimepicker stores location on leave?
Do we have a solution to this problem in 2005?
Because I don't see anything extra in the control that allows the focus to be set?
Re: [RESOLVED] [02/03] Datetimepicker stores location on leave?
Quote:
Originally Posted by 330hi
Do we have a solution to this problem in 2005?
Because I don't see anything extra in the control that allows the focus to be set?
Well, I don't think I really resolved it before, but I did the following and it works for 2003.
Code:
dateControl.Format = DateTimePickerFormat.Custom
dateControl.CustomFormat = "MM"
dateControl.CustomFormat = "MM/dd/yyyy"
dateControl is the datetimepicker control