Custom Hours in the Time Picker

6 posts, 1 answers
  1. Denis Cilliers
    Denis Cilliers avatar
    62 posts
    Member since:
    Jan 2004

    Posted 18 Feb 2013 Link to this post

    Is there a way to limit the hours displayed in the Time Picker as some times would not be allowed in the logic of the application but are displayed in the picker, such as 00:00 01:00 etc

    Can I remove these hours and have a range from say 07:00 to 21:00

    Thanks

    Denis
  2. Answer
    Peter
    Admin
    Peter avatar
    1148 posts

    Posted 21 Feb 2013 Link to this post

    Hi Denis,

    Thank you for writing.

    These hours cannot be removed from the table and I suggest to make them Disabled. To do this you can handle the TimeCellFormatting event and set Enabled to false if the time for this element is out of range. Please, refer to the code below:
    this.radTimePicker1.TimeCellFormatting += new Telerik.WinControls.UI.TimeCellFormattingEventHandler(radTimePicker1_TimeCellFormatting);
     
     
    void radTimePicker1_TimeCellFormatting(object sender, Telerik.WinControls.UI.TimeCellFormattingEventArgs e)
    {
        minTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 0, 0);
        maxTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 17, 0, 0);
        e.Element.Enabled = e.Element.Time >= minTime && e.Element.Time < maxTime;
    }

    I suggest to display Hours & Minutes in one table instead of two tables:
    this.radTimePicker1.TimeTables = Telerik.WinControls.UI.TimeTables.HoursAndMinutesInOneTable;

    Please, refer to the attached project.

    I hope this helps.

    All the best,
    Peter
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Denis Cilliers
    Denis Cilliers avatar
    62 posts
    Member since:
    Jan 2004

    Posted 21 Feb 2013 Link to this post

    Cool thank you it works nicely 
    For the Code Converter it seems to have an issue with Events, and again this answer like so many has an event handler.
    It does not add these parts very well 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
     
    AddHandler Me.RadTimePicker1.TimeCellFormatting, AddressOf radTimePicker1_TimeCellFormatting

    Thanks  it is now working 
  5. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 26 Feb 2013 Link to this post

    Hi Denis,

    We are aware of this limitation of the converter, please excuse us for the introduced inconvenience.

    The posts in the forum do not provide information about the programming language and unless you mention it we provide C# code.

    I hope that you find this information useful.

    Regards,
    Peter
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  6. Denis Cilliers
    Denis Cilliers avatar
    62 posts
    Member since:
    Jan 2004

    Posted 27 Feb 2013 Link to this post

    Hi Peter 

    You are very kind to offer to translate the C# to VB or even provide it in VB, The tool that Telerik provides is very good actually.

    It is just that this project atm is in VB, i'm sure my next will be in C# again, so don't worry about it keep providing it in C# as i'm sure that is what you are working on all the time.

    It also keeps us VB (current project) on our toes as we have to keep translating between the two languages and it makes us think about the code a bit more than I would if I just had to copy and paste.

    Thanks again for the hard work

    Denis
  7. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 28 Feb 2013 Link to this post

    You are welcome Denis. Let us know if you need anything else.

    Regards,
    Peter
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Join us for a FREE webinar to see all the new stuff in action.

    Interested, but can’t attend? Register anyway and we’ll send you the recording.
Back to Top
UI for WinForms is Visual Studio 2017 Ready