This is a migrated thread and some comments may be shown as answers.

Backcolor of cellelement based on appointment backgroun

1 Answer 57 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
AMF
Top achievements
Rank 2
AMF asked on 19 Sep 2012, 11:55 AM
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?

1 Answer, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 21 Sep 2012, 01:18 PM
Hello,

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);
        appointments.Add(e.AppointmentElement);
 
        foreach (AppointmentElement app in appointments)
        {
            if (cell.Date == app.Appointment.Start.Date)
            {
                shouldColor = true;
                break;
            }
        }
 
        if (shouldColor)
        {
            cell.BackColor = Color.Red;
        }
        else
        {
            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.

Greetings,
Ivan Todorov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
Scheduler and Reminder
Asked by
AMF
Top achievements
Rank 2
Answers by
Ivan Todorov
Telerik team
Share this question
or