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

Get appointment in CellFormatting event

4 Answers 136 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 20 Feb 2015, 04:23 PM
Hello,

Is it possible to determine if an appointment exists within the cell in the CellFormatting event?  What I'm trying to accomplish is to determine if the cell has an all day appointment inside of it, and if it does then color all of the remaining cells gray.

Any help would be greatly appreciated.

Kind regards,

David

4 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 24 Feb 2015, 12:51 PM
Hello David,

Thank you for contacting us.

To change background color of cells you need to subscribe to the CellFormatting event and check if current cell contains all day appointment.
private void radScheduler1_CellFormatting(object sender, SchedulerCellEventArgs e)
{
    if (!(e.CellElement is SchedulerHeaderCellElement))
    {
        foreach (Appointment appointment in this.radScheduler1.ActiveView.Appointments)
        {
            if (appointment.Duration.TotalDays > 1)
            {
                if (appointment.Start <= e.CellElement.Date && e.CellElement.Date <= appointment.End)
                {
                    e.CellElement.BackColor = Color.White;
                    e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
                }
                else
                {
                    e.CellElement.BackColor = Color.LightGray;
                    e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
                }
            }
            else
            {
                e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
            }
        }
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
    }
}

In order to update cells, if appointment is changed you can subscribe to the AppointmentChanged event.
private void radScheduler1_AppointmentChanged(object sender, AppointmentChangedEventArgs e)
{
    this.radScheduler1.ViewElement.UpdateCells();
}

I hope this helps. Should you have any additional questions do no hesitate to ask.

Regards,
Todor Vyagov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
David
Top achievements
Rank 1
answered on 24 Feb 2015, 05:58 PM
Hello Todor,

Thanks for the code, I appreciate it, however it only got me to a point so I had to change the code a little bit for it to do what's been requested.  I need the entire day to be greyed out if there's an appointment on that day and it's an all day appointment, so here's my code:

private void radScheduler1_CellFormatting(object sender, Telerik.WinControls.UI.SchedulerCellEventArgs e)
        {
            if (!(e.CellElement is SchedulerHeaderCellElement))
            {
                foreach (Appointment appointment in this.radScheduler1.ActiveView.Appointments)
                {
 
                    if (appointment.Duration.TotalDays == 1.0)
                    {
 
                        if (appointment.Start <= e.CellElement.Date && appointment.End.AddHours(23) >= e.CellElement.Date)
                        {
                            e.CellElement.BackColor = Color.Silver;
                            e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
                        }
                        else
                        {
                            e.CellElement.BackColor = Color.White;
                            e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
                        }
                    }
                }
            }
        }

However, this only sort of works.  If you create an all day appointment then the day gets greyed out with the silver color per the code, however if you're using a RadScheduleNavigator and you go past the appointment, so the appointment isn't on the screen, then use the RadScheduleNavigator to go back to the day with the appointment, when the appointment first appears the day is not greyed out, it's all white.  However, if you just single click on the RadScheduler control the day will get greyed out properly.

So this only works part of the time.  Is this a bug with the RadScheduler control?

Kind regards,

David
0
David
Top achievements
Rank 1
answered on 24 Feb 2015, 08:15 PM
Never mind, I figured out how to do it.  In Visual Basic my code is as follows, in the CellFormatting event:

For Each appt In schedAsset.ActiveView.Appointments
            If Not (TypeOf e.CellElement Is SchedulerHeaderCellElement) Then
                If appt.Start.Year = e.CellElement.Date.Year _
                    And appt.Start.Month = e.CellElement.Date.Month _
                    And appt.Start.Day = e.CellElement.Date.Day _
                    And appt.AllDay = True Then _
                    e.CellElement.BackColor = Color.Silver
            End If
        Next

This does exactly what I need, it colors the cells for the entire day but only if there's an all day appointment for that day.  

Thanks for pointing me in the right direction with the "ActiveView.Appointments" property.  I couldn't have figured this out without you showing me that property in your code!

Kind regards,

David Ayres
0
Todor
Telerik team
answered on 25 Feb 2015, 01:00 PM
Hi David,

I am glad you have managed to sort this out. 

If you have any future questions do not hesitate to contact us.

Regards,
Todor Vyagov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Scheduler and Reminder
Asked by
David
Top achievements
Rank 1
Answers by
Todor
Telerik team
David
Top achievements
Rank 1
Share this question
or