Hide or Block Time Slots

34 posts, 1 answers
  1. tom
    tom avatar
    4 posts
    Member since:
    Aug 2008

    Posted 26 May 2014 Link to this post

    I am using DayView with resource grouping on my scheduler. I need to be able to loop through all resources and grey out an entire day for a resource who is not working that day. ie I have 3 employees(resources), they schedule displays 3 days in day view(mon, tues, wed). Employee 2  is on vacation on Tuesday.  OR I would even be happy with display text in day header for  Tuesday that says "VACATION"

     Can you help me.  I have tried  various solutions here related to looping through cells but they don't seem to address groups by resource structure.

    Thanks!

    Tom
  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 29 May 2014 Link to this post

    Hello Tom,

    Thank you for writing.

    It is appropriate to use the CellFormatting event and change the style for the desired CellElement. Here is a sample code snippet, demonstrating how to disable all cells for a specific date and for a specific resource only:
    public Form1()
    {
        InitializeComponent();
     
        Color[] colors = new Color[]
        {
            Color.LightBlue, Color.LightGreen, Color.LightYellow,
            Color.Red, Color.Orange, Color.Pink, Color.Purple, Color.Peru, Color.PowderBlue
        };
     
        string[] names = new string[]
        {
            "Alan Smith", "Anne Dodsworth",
            "Boyan Mastoni", "Richard Duncan", "Maria Shnaider"
        };
     
        for (int i = 0; i < names.Length; i++)
        {
            Resource resource = new Resource();
            resource.Id = new EventId(i);
            resource.Name = names[i];
            resource.Color = colors[i];
            this.radScheduler1.Resources.Add(resource);      
        }
        this.radScheduler1.GroupType = GroupType.Resource;
        this.radScheduler1.GetDayView().ResourcesPerView = 2;
    }
     
    private void radScheduler1_CellFormatting(object sender, Telerik.WinControls.UI.SchedulerCellEventArgs e)
    {
        if (e.CellElement.Date.Month == 5 && e.CellElement.Date.Day == 30 &&
            e.CellElement.View.GetResources() != null && e.CellElement.View.GetResources().Count > 0 &&
            e.CellElement.View.GetResources()[0].Name == "Anne Dodsworth")
        {
            if (!(e.CellElement is SchedulerHeaderCellElement))
            {
                e.CellElement.Enabled = false;
            }
        }
        else
        {
            if (!(e.CellElement is SchedulerHeaderCellElement))
            {
                e.CellElement.ResetValue(VisualElement.EnabledProperty, ValueResetFlags.Local);
            }
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. tom
    tom avatar
    4 posts
    Member since:
    Aug 2008

    Posted 29 May 2014 in reply to Dess Link to this post

    Thank you this is very helpful and will solve my issue for color coding entire day. If I understand correctly this event fires every time the cell is created or used?
    That tells me that this logic gets processed many times per scheduler display (ie once per cell)? Which is fine when I am coloring an entire day.

    Sometimes I know exactly what resource and what date and I want to format ONLY the header cell on that date.  Without using the CellFormatting event, is there a way to directly address a specific header cell for that one date. im sure the answer is here using a collection  I just can't see it! Maybe SchedulerDayViewElement?

    Since I have to do a DB read to find my dates off, I want to minimize the reads to one per resource and then directly address that header cell for that one date.

    Hope this makes sense/ Thank you so much!

    Tom
  5. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 03 Jun 2014 Link to this post

    Hello Tom,

    Thank you for writing back.

    The CellFormatting event is fired after a SchedulerCellElement has been created, and when this cell needs to be displayed or refreshed. Note that RadScheduler uses element recycling in order to deliver better performance, hence it is not suitable to access directly a certain cell and customize it, because later it may contain data for another resource as it is being reused. That is why the appropriate way to customize a specific cell for a desired resource is to use the CellFormatting event. Here is a slight modification of the previous code example in order to customize only the SchedulerHeaderCellElement for the desired resource:
    private void radScheduler1_CellFormatting(object sender, Telerik.WinControls.UI.SchedulerCellEventArgs e)
    {
        if (e.CellElement is SchedulerHeaderCellElement)
        {
            if (e.CellElement.Date.Month == 6 && e.CellElement.Date.Day == 4 &&
                e.CellElement.View.GetResources() != null && e.CellElement.View.GetResources().Count > 0 &&
                e.CellElement.View.GetResources()[0].Name == "Anne Dodsworth")
            {
                e.CellElement.BackColor = Color.Red;
            }
            else
            {
                e.CellElement.ResetValue(VisualElement.BackColorProperty, ValueResetFlags.Local);
                 
            }
        }
    }

    In addition, I would recommend you to extract holidays data from the database in advance in order to avoid performance problems when extracting data in the CellFormatting event.

    I hope this information helps. If you have any additional questions, please let me know.  

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top