Updating RadScheduler with appointments collected on a background thread

2 posts, 0 answers
  1. Jill-Connie Lorentsen
    Jill-Connie Lorentsen avatar
    118 posts
    Member since:
    Nov 2008

    Posted 28 Aug 2014 Link to this post

    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
  2. Dess
    Dess avatar
    1561 posts

    Posted 02 Sep 2014 Link to this post

    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)

    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.

    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.
  3. DevCraft banner
Back to Top