After databind: update current view

3 posts, 1 answers
  1. Raoul
    Raoul avatar
    36 posts
    Member since:
    Apr 2012

    Posted 15 Dec 2012 Link to this post


    I have a client server solution. Several clients connect to a single database hosting the scheduler data. When a client changes the data in the database table (adding, removing, changing an appointment) the SQL message broker kicks in and all other clients execute a function to update their scheduler. So far this works like a charm:

    ''' <summary>
    ''' Sql Server notifies the scheduler table data is changed!
    ''' The current scheduler data needs to rebind to reflect the changes...
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub AgendaWijziging(sender As Object, e As System.Data.SqlClient.SqlNotificationEventArgs)
        If Me.InvokeRequired Then
            RadScheduler1.BeginInvoke(New MethodInvoker(AddressOf radScheduler1_rebind))
        End If
    End Sub
    ''' <summary>
    ''' Rebind the scheduler after a database change by another client
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub radScheduler1_rebind()
            Me.Cursor = Cursors.WaitCursor
            ' attempt to find current first time slot in view (user scrolled to this time slot)
            'Dim dayView As SchedulerDayViewGroupedByResourceElement = TryCast(Me.RadScheduler1.SchedulerElement.ViewElement, SchedulerDayViewGroupedByResourceElement)
            'Dim singleDayView As SchedulerDayViewElement = Nothing
            'Dim resetToTime As DateTime? = Nothing
            'Dim firstCell As SchedulerCellElement
            'If dayView IsNot Nothing Then
            '    singleDayView = dayView.GetDayViewElements.FirstOrDefault
            '    If singleDayView IsNot Nothing Then
            '        firstCell = singleDayView.DataAreaElement.Table.Children.First
            '        If firstCell IsNot Nothing Then
             '            resetToTime = CType(cell, SchedulerCellElement).Date (date only... no time?)
            '        End If
            '    End If
            'End If
           ' go back to the timeslot the user scrolled to.. (does not work :( resetToTime contains date only )
           'If singleDayView IsNot Nothing AndAlso resetToTime IsNot Nothing Then
           '    singleDayView.DataAreaElement.Table.ScrollToTime(New TimeSpan(resetToTime.Value.Hour, resetToTime.Value.Minute, resetToTime.Value.Second))
           'End If
           ' re-initialize the sql broker notification
        Catch ex As Exception
            Dim currentMethode As MethodBase = MethodBase.GetCurrentMethod
            FormHelper.LogError(ex, currentMethode.DeclaringType.ToString, currentMethode.ToString)
            Me.Cursor = Cursors.Arrow
        End Try
    End Sub

    The problem is in the commented code: After the databind is executed, the scheduler view is reset to 00:00 hour. I basically attempt to update the binding without updating the display, so when another workstation adds a appointment on a timeslot in view it just appears in the scheduler the user is looking at or (when in a timeslot out of view) would appear when scrolling. As an added bonus the scheduler contains several resources.

    So how can I "detect" the start or end of the top _visible_ timeslot and then use "dv.DataAreaElement.Table.ScrollToTime(TimeSpan.FromHours(firstCell.Hour))" to Update the view after databind?
    Or should I approach this differently?


  2. Answer
    Ivan Todorov
    Ivan Todorov avatar
    688 posts

    Posted 19 Dec 2012 Link to this post

    Hi Raoul,

    Thank you for contacting us.

    When using resource grouping, the scheduler displays multiple day view elements at a time and the approach is different. Please try the following code:
    //Save the scroll value
    SchedulerDayViewGroupedByResourceElement dayViewGroupingElement = this.scheduler.SchedulerElement.ViewElement as SchedulerDayViewGroupedByResourceElement;
    int saveScrollValue = 0;
    if (dayViewGroupingElement != null)
        saveScrollValue = dayViewGroupingElement.GetDayViewElements()[0].DataAreaElement.VScrollBar.Value;
    //Rebind the scheduler
    //Restore the scroll value
    dayViewGroupingElement = this.scheduler.SchedulerElement.ViewElement as SchedulerDayViewGroupedByResourceElement;
    if (dayViewGroupingElement != null)
        //TELERIKFIX - this fixes the issue with the scroll sync
        List<SchedulerDayViewElement> elements = dayViewGroupingElement.GetDayViewElements();
        elements[elements.Count - 1].DataAreaElement.ScrollView.Value = new Point(0, saveScrollValue);

    If you have any further questions or if you need further assistance, do not hesitate to write back.

    Kind regards,
    Ivan Todorov
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. Raoul
    Raoul avatar
    36 posts
    Member since:
    Apr 2012

    Posted 19 Dec 2012 Link to this post

    That did the trick! Thank you so much.

Back to Top