changing the background color of the time blocks on the scheduler

8 posts, 1 answers
  1. Andrew
    Andrew avatar
    4 posts
    Member since:
    Aug 2010

    Posted 30 Mar 2011 Link to this post

    I was wondering if there is any way that I would be able to manipulate the background of the scheduler screen for each time block under each resource.
    I would like to have two primary colors, smiler to the working time that is currently in place but instead of one time range of 7 - 5 across all resources I would like for each resource to have its own multiple time range.

    for example:

              |  Resource  1  |   Resource  2  |
    4am   |                       |                         |
              |       blue         |         blue         |
    5am   |                       |  ___________ |
              |                       |                         |
    6am   |                       |                         |
              |___________ |       white          |
    7am   |                       |                         |
              |       white        |                         |
    8am   |                       |                         |
              |                       | ___________  |
    9am   |                       |                         |
              |                       |        blue          |
    10am |                       |                         |
              |                       | ___________  |
    11am |                       |                         |
              |___________ |                         |
    12pm |                       |       white          |
              |        blue        |                         |
     1pm  |                       |                         |
              |                       |                         |
    2pm   |                       |                         |
              |                       |                         |
    3pm   |                       |                         |
              |                       |                         |
    4pm   |                       | ___________  |
              |                       |                        |
    5pm   |                       |                        |
              |                       |       blue          |
    6pm   |                       |                        |
              |                       |___________  |
    7pm   |                       |                         |
              |                       |                         |
    8pm   |                       |                         |
              |                       |                         |
    9pm   |                       |                         |
              |                       |        white         |
    10pm |                       |                         |
              |                       |                         |
    11pm |                       |                         |
              |                      |                          |
    12am |                       |                         |

    so each resource could have basically there own multiple different working times, with different colors.
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 04 Apr 2011 Link to this post

    Hello Andrew,

    Currently, such customization abilities are not supported by RadScheduler although we have plans to extend this functionality in the future. I have created a PITS item so you can vote for it. If more people vote for it, we will increase its priority. You can find the PITS item here.

    If you have any additional questions, feel free to ask.

    Kind regards,
    Ivan Todorov
    the Telerik team
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Andrew
    Andrew avatar
    4 posts
    Member since:
    Aug 2010

    Posted 04 Apr 2011 Link to this post

    ok thank you,

    Would it be possible earlier while we wait for that feature to become of a higher priority to make a function for example "SchedulerDayViewGroupedByResourceElement.SetCellsOpacity" overriadable and then I can do the work in our code for the time being.
  5. Answer
    Sean Overman
    Sean Overman avatar
    31 posts
    Member since:
    Sep 2012

    Posted 04 Apr 2011 Link to this post

    I too faced this problem.  I figured out a solution.

    You need to write your own method to figure out if a "resource" is available at a certain time -- IsEmployeeScheduled(int, datetime) in my case.


    if (Scheduler.ActiveViewType == SchedulerViewType.Day || Scheduler.ActiveViewType == SchedulerViewType.Week) {
        List<SchedulerDayViewElement> dayViews = null;
        //not sure why, but in weekview, the ViewElement is still of type "DayViewElement", so this cast is fine
        if (Scheduler.GroupType == GroupType.Resource) {
            dayViews = ((SchedulerDayViewGroupedByResourceElement)Scheduler.SchedulerElement.ViewElement).GetDayViewElements();
        } else {
            dayViews.Add((SchedulerDayViewElement)Scheduler.SchedulerElement.ViewElement);
        }
     
        foreach (SchedulerDayViewElement dve in dayViews) {
            int empID = (int)dve.View.GetResources()[0].Id.KeyValue;
     
            foreach (SchedulerCellElement sce in dve.DataAreaElement.Table.GetCells()) {
                if (IsEmployeeScheduled(empID, sce.Date)) {
                    sce.BackColor = Color.FromArgb(230, 230, 230);
                } else {
                    sce.BackColor = _unavailableColor;
                }
            }
        }
    }


    Telerik, can you tell me why the WeekView mode ViewElement is still of a DayViewElement type?

    Thanks and I hope this helps.
  6. Andrew
    Andrew avatar
    4 posts
    Member since:
    Aug 2010

    Posted 05 Apr 2011 Link to this post

    that worked great thank you.
  7. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 07 Apr 2011 Link to this post

    Hello Sean,

    Thank you for sharing your approach with us.

    In regards to your question, WeekView's view element is still of DayViewElement type because both views have the same functionality, just the range is different.

    Your Telerik points have been updated for your community effort.

    @Andrew:
    I am glad you have found a solution

    If you have any further questions, do not hesitate to ask.

    All the best,
    Ivan Todorov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Andrew
    Andrew avatar
    4 posts
    Member since:
    Aug 2010

    Posted 09 Apr 2012 Link to this post

    has there been any changes to the functionality that would cause the background colors to reset when scrolling left to right. this process works great but when I scroll left to view the other items all customized background colors change to there default color.  Or would it be a requirement to set the color as you scroll. 

    As a side note we did try to register to try to find out what might have changed the value;
     - LayoutUpdated
     - PropertyChanged
     - RadPropertyChanged

    the first time we scroll or go into the calendar the events fire, but after we scrolled once the events get unregistered and the colors get reverted, would there any suggestion to prevent this from occurring.

    we dont recall seeing this issue when we first implemented the color changing events, so it could possibly be from a upgrade we are now on 2012.1.301, or we could have missed it.

    Thank you
  9. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 12 Apr 2012 Link to this post

    Hello Andrew,

    I am not sure to which event you add the code that Sean posted. Generally, RadScheduler recycles its elements regularly and this might be the reason for loosing your handlers. However, with version 2012.1.301, you should be able to use the CellFormatting event for achieving this scenario:
    this.radScheduler1.CellFormatting += new EventHandler<SchedulerCellEventArgs>(radScheduler1_CellFormatting);
    this.radScheduler1.ActiveView = new SchedulerDayView();
     
    void radScheduler1_CellFormatting(object sender, SchedulerCellEventArgs e)
    {
        int empId = (int)e.CellElement.View.GetResources()[0].Id.KeyValue;
     
        if (IsEmployeeScheduled(empId, e.CellElement.Date))
        {
            e.CellElement.BackColor = Color.Red;
        }
        else
        {
            e.CellElement.ResetValue(SchedulerCellElement.BackColorProperty, ValueResetFlags.Local);
        }
    }

    Please note that in order to get it fired initially, you should change the view after you have subscribed to it.

    I hope this will work for you.

    Greetings,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready