Backcolor of cellelement based on appointment backgroun

2 posts, 0 answers
  1. AMF
    AMF avatar
    34 posts
    Member since:
    Mar 2011

    Posted 19 Sep 2012 Link to this post

    Hi all.

    Currently I'm working on a planning module. To display the different shifts of the employees I'm using recurring appointments.

    In the Timeline view I would like to color the background of the scheduler cell instead of displaying the recurring appointment. I'm trying to get this done in the AppointmentFormatting event, because that's where I have all the information I need to achieve this. But I can't figure out how to get the CellElement of that day. 

    So is there a way of getting a cell element for the appointment?
  2. Ivan Todorov
    Ivan Todorov avatar
    688 posts

    Posted 21 Sep 2012 Link to this post


    Thank you for contacting us.

    To achieve this scenario, you should iterate through all the cells and all appointments to determine if a given cell contains an appointment. The following code snippet demonstrates this:
    void radScheduler1_AppointmentFormatting(object sender, Telerik.WinControls.UI.SchedulerAppointmentEventArgs e)
        foreach (SchedulerCellElement cell in SchedulerUIHelper.GetCells(this.radScheduler1))
            DateTime cellDate = cell.Date;
            bool shouldColor = false;
            List<AppointmentElement> appointments = SchedulerUIHelper.GetAppointmentElements(this.radScheduler1);
            foreach (AppointmentElement app in appointments)
                if (cell.Date == app.Appointment.Start.Date)
                    shouldColor = true;
            if (shouldColor)
                cell.BackColor = Color.Red;
                cell.ResetValue(SchedulerCellElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);

    Note that this will only work for day scale. The approach for different scales would be the same, but you will need to sort the cells by date and check if the start of an appointment falls in the time span that a cell represents.

    I hope I was able to help. Do not hesitate to write back if you need any further help.

    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. DevCraft banner
Back to Top