Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Collapse]Scheduler
   [Expand]Product Information
   [Collapse]Getting Started
     Lesson 1 - Create a Simple Scheduling Application
     Lesson 2 - Create a Simple Scheduling Application with DateNavigator
     Lesson 3 - Provide Bar UI for a Scheduler
     Lesson 4 - Provide Ribbon UI for a Scheduler
     Lesson 5 - Bind a Scheduler to MS SQL Database at Design Time
     Lesson 6 - Bind a Scheduler to MS Access Database at Design Time
     Lesson 7 - Create a Custom Appointment Edit Form
     Lesson 8 - Implement a Custom Inplace Editor
   [Expand]Fundamentals
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End-User Capabilities
   [Expand]Member Tables
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Lesson 5 - Bind a Scheduler to MS SQL Database at Design Time

This document describes how to bind a SchedulerControl to a sample MS SQL Server database at design time.

To bind a SchedulerControl to a BindingSource, follow the instructions below.

Expanded Create a New Project

  1. Create a new Windows Forms Application project in Visual Studio.
  2. Drop the SchedulerControl item from the DX.17.1: Scheduling toolbox tab onto the form.

  3. Click the smart tag icon at the top right of the control () to display its actions list. Select Dock in Parent Container. This will stretch the SchedulerControl to fill the entire form.

Expanded Create a Database

  1. In the Tools menu of the Visual Studio IDE select Connect to Database.... The Add Connection dialog is invoked.

    Type in a name of the new database file - SchedulerTest, as illustrated in the picture above. Click OK to create a new database and a connection.

  2. In the Server Explorer window right-click the newly created data connection and select New Query to open a new query window.

  3. Switch to the form with the SchedulerControl, select the Scheduler Control, and click the smart tag icon at the top right of the control () to display its actions list. Click the Create Sample Database item to invoke a window that contains SQL script. Click the Copy to Clipboard and Close button.

  4. Switch to the SQLQuery window and paste the script in a window. Execute the query.

    The query will create tables for Appointments and Resources within the SchedulerTest database.

Expanded Connect to a Database

  1. Switch to the Visual Studio project, select the Scheduler Control, and click the smart tag icon to display its actions list. Click the Appointments Data Source drop-down and select the Add Project Data Source… link to invoke the Data Source Configuration Wizard.

  2. Select the Database icon and click Next.
  3. On the following page, select the Dataset database model and click Next.
  4. Select a connection to the SchedulerTest database created in step 7 and click Next. You are prompted to copy the data file to your project, click Yes.
  5. In the next page, click Next to save the connection as SchedulerTestConnectionString.
  6. When prompted to choose your database objects, select the Appointments and Resources tables.

  7. Click Finish.
  8. You have copied the data file SchedulerTest.mdf to the project folder. Specify that it should be copied to the output directory only if the source file is newer than the working database, otherwise your data will be overwritten when the project runs next time. For this, change its property as illustrated in the picture below.

Expanded Bind a Scheduler to Data

  1. In the SchedulerControl's action list (invoked by the smart tag), click the Appointments Data Source drop-down and select the Appointments table.

    As a result, Visual Studio will generate a set of classes and components. The following three components will appear in the tray: schedulerTestDataSet, appointmentsBindingSource and appointmentsTableAdapter.

  2. Click Mappings Wizard... in the smart tag panel to invoke the Setup Appointment Storage window. Click the Generate button. All required mappings are generated automatically. Check to see if they are correct and click Finish.

    To set up mappings later, in the SchedulerControl's actions list (invoked by the smart tag), click the Mappings Wizard... link in the Appointments section.

    Tip

    Review the Mappings topic for more information on the mapping concept.

  3. In the SchedulerControl's actions list (invoked by the smart tag), click the Resources Data Source drop-down and select the Resources table.

    As a result, two new components will appear in the tray - resourcesBindingSource and resourcesTableAdapter.

  4. Click Mappings Wizard... in the smart tag panel to invoke the Setup Resource Storage window. Click the Generate button. All required mappings are generated automatically. Set the ParentId mapping to none since it is required for the Gantt View only. Check to see if mappings are correct and click Finish.

  5. Note that after the scheduler storage has been bound to data, the scheduler control will not automatically show its data at design time. Also, if the project is run at this stage, the scheduler control will also be empty, as the underlying schedulerTestDataSet does not contain data. The code used to populate table adapters at runtime is automatically added to the form's Load event.

Expanded Specify Initial Settings

Expanded Post Data Back to the Database

You can run the project and start editing data. The changes will be saved in the underlying DataTable objects, but they will not be saved in the database. To complete the example, write the code that posts the changes in the schedulerTestDataSet back to the database. Handle the SchedulerStorageBase.AppointmentsChanged, SchedulerStorageBase.AppointmentsDeleted and SchedulerStorageBase.AppointmentsInserted events, and include the code that saves changes into the event hander.

Expanded Result

The code written by following this step-by-step guide is shown below.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T341685.

Run the project. The following image shows the running application.

Expanded See Also

How would you rate this topic?​​​​​​​