|
-
Mar 31st, 2006, 10:21 AM
#1
Thread Starter
Lively Member
[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!
Last edited by Hack; Mar 31st, 2006 at 10:50 AM.
-
Mar 31st, 2006, 10:34 AM
#2
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 31st, 2006, 10:39 AM
#3
Member
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
-
Mar 31st, 2006, 10:43 AM
#4
Re: Datetimepicker stores location on leave?
Hes interested in setting the focus to the month part and not setting its value.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 31st, 2006, 10:50 AM
#5
Member
Re: [02/03] Datetimepicker stores location on leave?
ahh, i realy should read things properly
-
Mar 31st, 2006, 10:51 AM
#6
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.
-
Mar 31st, 2006, 10:51 AM
#7
Thread Starter
Lively Member
Re: Datetimepicker stores location on leave?
 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).
-
Mar 31st, 2006, 10:58 AM
#8
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 30th, 2008, 11:26 AM
#9
New Member
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?
-
Sep 30th, 2008, 01:11 PM
#10
Thread Starter
Lively Member
Re: [RESOLVED] [02/03] Datetimepicker stores location on leave?
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|