Results 1 to 4 of 4

Thread: [RESOLVED] [2.0] DateTimePicker Increments

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Resolved [RESOLVED] [2.0] DateTimePicker Increments

    Hey guys. I am using a DateTimePicker on my form with the ShowUpDown property set to true. Would it be

    possible to make it so when you click up on the minutes side, it goes up by 15? Like.. Here's an example

    The DateTimePicker says this:

    05:00

    The 05 is the hours and the 00 is the minutes

    Anyways, you have the 00 selected and you click up once and then it goes right up to 05:15, then 05:30, etc...

    etc.. Thanks for any help

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

    Re: [2.0] DateTimePicker Increments

    It wouldn't really make sense to do that because while you may want the minutes to increment by 15 at a time, would you want the hours to do the same? If you want to force the time to always be at a quarter hour you could handle the ValueChanged event and then round the time to a quarter hour. It would be tricky though because if you simply round the time then you'll never be able to change it using the arrows because it will always round back to the same time. You would have to keep the previous time in a variable and in the event handler compare the new time to that to know whether to round up or down. Then you'll also have to take into account when the user types in a new time so the difference will not be just one minute.
    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2.0] DateTimePicker Increments

    Nevermind, Conipto helped me. It all works now

    Oh, and so iPrank isn't raggin' on me again.. here :P

    Code:
            private DateTime[] last = new DateTime[12];
            private void dateTimePickers(object sender)
            {
    
                DateTimePicker DT = (DateTimePicker)sender;
                int min = 0;
                if ((DT.Value.Minute == 0) | (DT.Value.Minute == 15) | (DT.Value.Minute == 30) | (DT.Value.Minute == 45)) return;
                if (DT.Value.Minute > last[Convert.ToInt32(DT.Tag)].Minute)
                {
                    switch (DT.Value.Minute)
                    {
                        case 1: min = 15; break;
                        case 16: min = 30; break;
                        case 31: min = 45; break;
                        case 59: min = 45; break;
                    }
                }
                else
                {
                    switch (DT.Value.Minute)
                    {
                        case 44: min = 30; break;
                        case 29: min = 15; break;
                        case 14: min = 0; break;
                    }
                }
                DT.Value = new DateTime(DT.Value.Year, DT.Value.Month, DT.Value.Day, DT.Value.Hour, min, 0);
                last[0] = firststartbox.Value;
                last[1] = firstendbox.Value;
                last[2] = secondstartbox.Value;
                last[3] = secondendbox.Value;
                last[4] = thirdstartbox.Value;
                last[5] = thirdendbox.Value;
                last[6] = fourthstartbox.Value;
                last[7] = fourthendbox.Value;
                last[8] = fifthstartbox.Value;
                last[9] = fifthendbox.Value;
                last[10] = sixthstartbox.Value;
                last[11] = sixthendbox.Value;
            }
    And to call it from a ValueChanged event handler
    Code:
    dateTimePickers(((DateTimePicker)sender));
    Normally, I would just use EventArgs and stuff and just use it globally from the events tab in the properties window but I am performing other statements in the valuechanged event handler, so it wouldn't make sense to do that
    Last edited by Fromethius; Apr 14th, 2006 at 10:50 PM.

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: [2.0] DateTimePicker Increments

    Quote Originally Posted by Fromethius
    Oh, and so iPrank isn't raggin' on me again.. here :P
    Use the small case :p.

    Sorry, couldn't resist.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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