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

Updating RadScheduler with appointments collected on a background thread

1 Answer 140 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Jill-Connie Lorentsen
Top achievements
Rank 1
Jill-Connie Lorentsen asked on 28 Aug 2014, 11:46 AM
I have a data bound scheduler, with a SchedulerBindingSource:
private void InitiateBookingDataSource()
        {
            if (_appointmentBookings == null) _appointmentBookings = new BindingList<Booking>();
 
            var dataSource = new SchedulerBindingDataSource();
            var mappingInfo = new AppointmentMappingInfo
            {
                Start = "StartTime",
                End = "EndTime",
                Summary = "BookingSubject",
                Description = "BookingDescription",
                BackgroundId = "BackgroundId",
                AllDay = "AllDay",
                RecurrenceRule = "RecurrenceRule",
                Exceptions = "Exceptions",
                MasterEventId = "MasterEventId",
                Visible = "Visible"
            };
 
            mappingInfo.Mappings.Add(new SchedulerMapping("CaseId", "CaseId"));
            mappingInfo.Mappings.Add(new SchedulerMapping("PratId", "PratId"));
            mappingInfo.Mappings.Add(new SchedulerMapping("InterpretorId", "InterpretorId"));
            mappingInfo.Mappings.Add(new SchedulerMapping("BoothId", "BoothId"));
            mappingInfo.Mappings.Add(new SchedulerMapping("CaseDesc", "CaseDesc"));
            mappingInfo.Mappings.Add(new SchedulerMapping("InterpretorDesc", "InterpretorDesc"));
            mappingInfo.Mappings.Add(new SchedulerMapping("BoothDesc", "BoothDesc"));
 
            dataSource.EventProvider.Mapping = mappingInfo;
            dataSource.EventProvider.DataSource = _appointmentBookings;
            dataSource.EventProvider.AppointmentFactory = rsBookings.AppointmentFactory;
 
            rsBookings.DataSource = dataSource;
        }


I use async await to get appointments from the database, and on this background thread I also add the appointments to a binding list.

After this work is done I want to update the scheduler by adding the binding list from the background thread to the scheduler's binding list on the UI thread.

_appointmentBookings = await GetDataAsync(_cancellation.Token);
 This doesn't fire the Appointments_CollectionChanged event, and the scheduler is not updated

Is there a way to do this in one go? I've done some investigation, and updating the scheduler one appointment at a time seems to fire the Appointments_CollectionChanged event, but this is very time consuming. Another option is to call the InitiateBookingDataSource() method again, but I don't like that solution either.

Regards, Jill-Connie Lorentsen

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Sep 2014, 08:47 AM
Hello Jill-Connie,

Thank you for writing.

Please refer to our Scheduler >> Data Binding Walkthrough help article which is quite useful about setting up the RadScheduler with data. If your requirement is to refresh the data in RadScheduler with data coming from the database, you need to call the Fill method of the table adapter and pass the collection which you need to re-fill, in this case the appointments. This will cause the data to be refreshed. Refer to the sample code below:  
void refreshBtn_Click(object sender, EventArgs e)
{
    this.appointmentsTableAdapter.Fill(this.schedulerDataDataSet.Appointments);
}

Note that all UI controls are not thread safe controls in the whole Windows Forms platform (not just Telerik controls, but all controls out there). Here is an article on MSDN, describing how to make thread-safe Winforms UI application. This means that any control from the Telerik UI for WinForms suite is not thread safe as well and cannot be used outside the main UI thread. You should use an Invoke to update the controls in cross threading scenario.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Scheduler and Reminder
Asked by
Jill-Connie Lorentsen
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or