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

After databind: update current view

2 Answers 99 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Raoul
Top achievements
Rank 1
Raoul asked on 15 Dec 2012, 06:07 PM
Hi,

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))
    Else
        radScheduler1_rebind()
    End If
End Sub
 
 
''' <summary>
''' Rebind the scheduler after a database change by another client
''' </summary>
''' <remarks></remarks>
Private Sub radScheduler1_rebind()
    Try
        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
 
        RadScheduler1.DataBind()
 
       ' 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
        _context.MonitorAgenda()
 
        
    Catch ex As Exception
        Dim currentMethode As MethodBase = MethodBase.GetCurrentMethod
        FormHelper.LogError(ex, currentMethode.DeclaringType.ToString, currentMethode.ToString)
    Finally
        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?


regards,
Raoul

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 19 Dec 2012, 03:34 PM
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)
{
    dayViewGroupingElement.UpdateLayout();
 
    //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);
    dayViewGroupingElement.InvalidateMeasure(true);
    dayViewGroupingElement.UpdateLayout();
}

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.
0
Raoul
Top achievements
Rank 1
answered on 19 Dec 2012, 07:22 PM
That did the trick! Thank you so much.

Regards,
Raoul
Tags
Scheduler and Reminder
Asked by
Raoul
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Raoul
Top achievements
Rank 1
Share this question
or