Results 1 to 10 of 10

Thread: [RESOLVED] [02/03] Datetimepicker stores location on leave?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    104

    Resolved [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.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3
    Member
    Join Date
    Jan 2006
    Location
    Manchester UK
    Posts
    55

    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

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5
    Member
    Join Date
    Jan 2006
    Location
    Manchester UK
    Posts
    55

    Re: [02/03] Datetimepicker stores location on leave?

    ahh, i realy should read things properly

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    104

    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).

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  9. #9
    New Member
    Join Date
    Sep 2008
    Posts
    3

    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?

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    104

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width