Get appointment in CellFormatting event

5 posts, 0 answers
  1. David
    David avatar
    15 posts
    Member since:
    Jun 2014

    Posted 20 Feb 2015 Link to this post

    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
  2. Todor Vyagov
    Admin
    Todor Vyagov avatar
    31 posts

    Posted 24 Feb 2015 Link to this post

    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.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. David
    David avatar
    15 posts
    Member since:
    Jun 2014

    Posted 24 Feb 2015 in reply to Todor Vyagov Link to this post

    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
  5. David
    David avatar
    15 posts
    Member since:
    Jun 2014

    Posted 24 Feb 2015 Link to this post

    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
  6. Todor Vyagov
    Admin
    Todor Vyagov avatar
    31 posts

    Posted 25 Feb 2015 Link to this post

    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.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready