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

radScheduleView disappears after changing datasource in code

1 Answer 72 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 07 Nov 2011, 11:44 AM
I have a Lightswitch application that uses the scheduler is in a Silverlight user control.
The datasource is a Lightswitch screen based query that is passed in code as per the Telerik example Lightswitch Extension project here.
I am filtering the data on the visibledaterange of the scheduler because Lightswitch dies trying to pass a list of all 38,000 records in the appointments database (as in this thread).

On first activation of the screen the scheduler works fine. On changing visibledaterange it disappears. I can step through the code below and it all seems to work. But when focus returns to the screen, the scheduler appears as an empty grey box.

How do I refresh it?

Code behind the Lightswitch page to handle the filtering of the data so that the datasource is limited to visible appointments only:
       Private Sub SAControl_ControlAvailable(ByVal sender As Object, ByVal e As ControlAvailableEventArgs)
            rsvc = TryCast(e.Control, MyScheduleView)
            AddHandler CType(rsvc, MyScheduleView).VisibleRangeChanged, AddressOf Schedule_RangeChanged
       End Sub
       Private Sub Schedule_RangeChanged()
            Me.StartDate = CType(rsvc, MyScheduleView).VisibleRangeStart            'optional parameter of DataAppointments query
            Me.EndDate = CType(rsvc, MyScheduleView).VisibleRangeFinish           'optional parameter of DataAppointments query
            Me.DataAppointments.Load()
            rsvc.GetLSAppointments(Me.DataAppointments.ToList())
       End Sub

This code runs behind the Silverlight user control:
 Public Sub GetLSAppointments(ByVal myAppointments As List(Of DataAppointment))
            _coreAppointments.Clear()
            For Each scheduledAppointment As DataAppointment In myAppointments
                Dim appt As AppointmentConsult = MakeAppointment(scheduledAppointment)
                _coreAppointments.Add(appt)
            Next

            Dispatcher.BeginInvoke(Sub()
                                       xScheduleView.AppointmentsSource = Nothing
                                       xScheduleView.AppointmentsSource = _coreAppointments
                                   End Sub)
End Sub


1 Answer, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 08 Nov 2011, 12:25 PM
Found a solution. Might help someone else.

This is a different way to trigger a reload of the data filtered on current visibledaterange. Have to use the screen dispatcher to communicate with the Lightswitch screen from the Silverlight user control containing the scheduleview. The code in the previous post above seems to work when you debug through it, but it fails to send data back to the user control and update the scheduler datasource.

So here is how to filter the appointments data sent from the Lightswitch screen to the radscheduleview based on the schedulers visible date range:

1. In the Lightswitch screen, create two datepicker controls named StartDate and EndDate. Make them optional parameters to the query behind the screen and make them invisible.

2. In the code behind the user control create an event handler for the scheduleview:
Private Sub xScheduleView_VisibleRangeChanged(sender As Object, e As System.EventArgs) Handles xScheduleView.VisibleRangeChanged
            VisibleRangeChange(Me.xScheduleView.VisibleRange.Start, Me.xScheduleView.VisibleRange.End)
End Sub:

Private Sub VisibleRangeChange(start As Date, finish As Date)
            Dim objDataContext = DirectCast(Me.DataContext, IContentItem)
            Dim Screen = DirectCast(objDataContext.Screen, Microsoft.LightSwitch.Client.IScreenObject)
            Screen.Details.Dispatcher.BeginInvoke(Sub()
                                                      TryCast(Screen, YourScreenName).StartDate = start
                                                      TryCast(Screen, YourScreenName).EndDate = finish
                                                      TryCast(Screen, YourScreenName).Requery()
                                                  End Sub)
        End Sub
3. In the code behind the Lightswitch screen:
Private Sub DataAppointments_Loaded(succeeded As Boolean) 'this event handler fires whenever the screen query has completed execution
            If succeeded Then
                PushDataToSchedule()
            End If
End Sub

Private Sub PushDataToSchedule()
            Try
                'rsvc is a pointer to the scheduleview - created as per the code in the Telerik example (Lightswitch Extension) project
                'GetLSAppointments() is a function also in that project
                rsvc.GetLSAppointments(Me.DataAppointments.ToList())
            Catch
            End Try
End Sub

Public Sub Requery() 'called by the usercontrol whenever the visible date range has changed
            Try
                Me.DataAppointments.Load()
            Catch
            End Try
End Sub
Tags
ScheduleView
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Share this question
or