ScrollControlIntoView (AppointmentElement)

4 posts, 1 answers
  1. Raoul
    Raoul avatar
    33 posts
    Member since:
    Apr 2012

    Posted 13 Apr 2012 Link to this post

    How can I scroll a appointment into view?

    I can set focus to it, but when it's not in view, i can't seem to scroll to it. This is my code:
    Private Sub FocusAppointment(afspraak As Agenda)
     
            Dim app As Appointment = RadScheduler1.Appointments.FirstOrDefault(Function(c) c.UniqueId.KeyValue.Equals(afspraak.AgendaID))
     
            If app IsNot Nothing Then
                For Each appElement As AppointmentElement In SchedulerUIHelper.GetAppointmentElements(RadScheduler1)
                    Dim evnt As IEvent = appElement.Appointment
                    If evnt.UniqueId.KeyValue = afspraak.AgendaID Then
                        RadScheduler1.FocusedElement = appElement
                        RadScheduler1.ScrollControlIntoView(appElement) '<- Telerik.WinControls.UI.AppointmentElement' cannot be converted to 'System.Windows.Forms.Control
                    End If
                Next
            End If
     
        End Sub

    When commenting the 'scrollintoview-line' the code works and the selected appointment does get focus, but out of view...
    I obviously overlook something here.

    Kind Regards,
    Raoul
  2. Answer
    Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 18 Apr 2012 Link to this post

    Hi Raoul,

    Thank you for writing.

    The ScrollControlIntoView method comes from the base implementation of the ScrollableControl in .NET Framework and it works only with nested controls. However, the structure of our controls consists of visual elements called RadElements that are not actually controls.

    As to your current requirement, you can use the BringAppointmentIntoView method of the static SchedulerUIHelper class to achieve the desired functionality:
    SchedulerUIHelper.BringAppointmentIntoView(appElement.Appointment, RadScheduler1) ' instead of RadScheduler1.ScrollControlIntoView(appElement)

    I hope this will help you. Do not hesitate to ask if you have any further questions.

    All the best,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Raoul
    Raoul avatar
    33 posts
    Member since:
    Apr 2012

    Posted 21 Apr 2012 Link to this post

    Ivan,
    Thanks for your reply. Turned out this method is not available in 2011Q2. I'm doing maintenance on software for a new client which uses the 2011Q2 winforms controls. Anyway, turns out RadScheduler.GetChildAtPoint returns a control :)

    RadScheduler1.ScrollControlIntoView(RadScheduler1.GetChildAtPoint(appElement.Location))

    Regards,
    Raoul
  5. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 23 Apr 2012 Link to this post

    Hello Raoul,

    Indeed, the BringAppointmentIntoView method is not available in Q2 2011. I am posting here the code of this method so you can use it with the Q2 2011 version:
    public static void BringAppointmentIntoView(IEvent appointment, RadScheduler scheduler)
    {
        scheduler.ActiveView.StartDate = appointment.Start.AddDays(-1);
     
        int resIndex = scheduler.Resources.IndexOf(scheduler.Resources.GetById(appointment.ResourceId));
     
        SchedulerDayViewGroupedByResourceElement dayViewGrouped = scheduler.SchedulerElement.ViewElement as SchedulerDayViewGroupedByResourceElement;
        SchedulerMonthViewGroupedByResourceElement monthViewGrouped = scheduler.SchedulerElement.ViewElement as SchedulerMonthViewGroupedByResourceElement;
        TimelineGroupingByResourcesElement timelineGrouped = scheduler.SchedulerElement.ViewElement as TimelineGroupingByResourcesElement;
     
        if (dayViewGrouped != null)
        {
            dayViewGrouped.NavigateToResource(resIndex);
            foreach (SchedulerDayViewElement dvElement in dayViewGrouped.GetDayViewElements())
            {
                dvElement.DataAreaElement.Table.ScrollToTime(TimeSpan.FromHours(appointment.Start.Hour));
            }
        }
        if (monthViewGrouped != null)
        {
            monthViewGrouped.NavigateToResource(resIndex);
        }
        if (timelineGrouped != null)
        {
            timelineGrouped.NavigateToResource(resIndex);
        }
     
        SchedulerDayViewElement dayViewElement = scheduler.SchedulerElement.ViewElement as SchedulerDayViewElement;
     
        if (dayViewElement != null)
        {
            dayViewElement.DataAreaElement.Table.ScrollToTime(TimeSpan.FromHours(appointment.Start.Hour));
        }
    }

    I hope this will help you. If you have any additional questions, feel free to ask.

    All the best,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top