windowsforms-10699-controls-and-libraries-scheduler-examples-gantt-view-how-to-create-a-gantt-chart-application.md
To create an application to enable the Gantt View functionality, follow the instructions below.
In the Tools menu of the Visual Studio IDE select Connect to Database…. The Add Connection dialog is invoked.
In the Server Explorer window right-click the newly created data connection and select New Query to open a Query editor window that allows you to enter and execute scripts for this database.
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 for Gantt View item to invoke a window that contains SQL script. Click the Copy to Clipboard and Close button.
Switch to the SQLQuery window and paste the script in a window. Click Execute
Next, fill the Resource table with sample data. To do this, copy the script from the Hierarchical Resource Specifics document starting from SET IDENTITY_INSERT. Delete the content of the previous script in the query window, paste the new one and click Execute.
Use the Project/Add New Data Source menu command in Visual Studio to invoke a Data Source Configuration wizard. Specify the database connection string and include tables for resources, appointments and dependencies (Resources, Tasks and TaskDependencies tables in our example). Specify the name for the dataset - GantTestDataSet.
Click the Scheduler control’s smart tag and specify the Appointments table in the GantTestDataSet as the Appointments Data Source.
The Mappings Wizards (Setup Appointment Storage dialog) is invoked automatically. Select the Gantt view mappings checkbox to map fields containing the appointment identifier and Percent Complete value. Use Clear and Generate buttons to generate mappings automatically.
Click the Scheduler control’s smart tag and specify the Resources table in the GantTestDataSet as the Resources Data Source.
Click the Mappings Wizard… link for Resources data source and then Next to navigate to Custom Properties Mapping dialog. Map IdSort field to a corresponding custom property of a resource as illustrated below.
Click the Scheduler control’s smart tag and specify the TaskDependencies table in the GantTestDataSet as the AppointmentDependencies Data Source.
In Visual Studio Designer, open the ResourcesTree control’s smart tag and click Run Designer. The Tree List Designer is invoked. Double-click IdSort , Id and Description fields in the field list to add them to the list of displayed columns.
Move the IdSort field to the top of the list so it becomes the principal sort field, specify its sort order and hide the IdSort and Id fields by setting their Visible property to false.
In this example, table adapters are created automatically using Visual Studio wizards. This technique ensures that all Insert, Update and Delete statements are generated automatically and the identity fields are treated properly. Nevertheless, XtraScheduler specifics require modification of the data set, as shown in the following picture.
schedulerStorage1.AppointmentsInserted += new PersistentObjectsEventHandler(schedulerStorage1_AppointmentsInserted);
schedulerStorage1.AppointmentsChanged += new PersistentObjectsEventHandler(schedulerStorage1_AppointmentsChanged);
schedulerStorage1.AppointmentsDeleted += new PersistentObjectsEventHandler(schedulerStorage1_AppointmentsDeleted);
private void schedulerStorage1_AppointmentsChanged(object sender, PersistentObjectsEventArgs e) {
CommitTask();
}
private void schedulerStorage1_AppointmentsDeleted(object sender, PersistentObjectsEventArgs e) {
CommitTask();
}
private void schedulerStorage1_AppointmentsInserted(object sender, PersistentObjectsEventArgs e) {
CommitTask();
schedulerStorage1.SetAppointmentId(((Appointment)e.Objects[0]), id);
}
void CommitTask() {
appointmentsTableAdapter.Update(gantTestDataSet.Tables("Appointments"));
this.gantTestDataSet.Tables("Appointments").AcceptChanges();
}
AddHandler schedulerStorage1.AppointmentsInserted, AddressOf schedulerStorage1_AppointmentsInserted
AddHandler schedulerStorage1.AppointmentsChanged, AddressOf schedulerStorage1_AppointmentsChanged
AddHandler schedulerStorage1.AppointmentsDeleted, AddressOf schedulerStorage1_AppointmentsDeleted
Private Sub schedulerStorage1_AppointmentsChanged(ByVal sender As Object, ByVal e As PersistentObjectsEventArgs)
CommitTask()
End Sub
Private Sub schedulerStorage1_AppointmentsDeleted(ByVal sender As Object, ByVal e As PersistentObjectsEventArgs)
CommitTask()
End Sub
Private Sub schedulerStorage1_AppointmentsInserted(ByVal sender As Object, ByVal e As PersistentObjectsEventArgs)
CommitTask()
schedulerStorage1.SetAppointmentId((CType(e.Objects(0), Appointment)), id)
End Sub
Private Sub CommitTask()
appointmentsTableAdapter.Update(gantTestDataSet.Tables("Appointments"))
Me.gantTestDataSet.Tables("Appointments").AcceptChanges()
End Sub
schedulerStorage1.AppointmentDependenciesInserted += new PersistentObjectsEventHandler(schedulerStorage1_AppointmentDependenciesInserted);
schedulerStorage1.AppointmentDependenciesChanged += new PersistentObjectsEventHandler(schedulerStorage1_AppointmentDependenciesChanged);
schedulerStorage1.AppointmentDependenciesDeleted += new PersistentObjectsEventHandler(schedulerStorage1_AppointmentDependenciesDeleted);
private void schedulerStorage1_AppointmentDependenciesChanged(object sender, PersistentObjectsEventArgs e) {
CommitTaskDependency();
}
private void schedulerStorage1_AppointmentDependenciesDeleted(object sender, PersistentObjectsEventArgs e) {
CommitTaskDependency();
}
private void schedulerStorage1_AppointmentDependenciesInserted(object sender, PersistentObjectsEventArgs e) {
CommitTaskDependency();
}
void CommitTaskDependency() {
taskDependenciesTableAdapter.Update(this.gantTestDataSet.Tables("TaskDependencies"));
this.gantTestDataSet.Tables("TaskDependencies").AcceptChanges();
}
AddHandler schedulerStorage1.AppointmentDependenciesInserted, AddressOf schedulerStorage1_AppointmentDependenciesInserted
AddHandler schedulerStorage1.AppointmentDependenciesChanged, AddressOf schedulerStorage1_AppointmentDependenciesChanged
AddHandler schedulerStorage1.AppointmentDependenciesDeleted, AddressOf schedulerStorage1_AppointmentDependenciesDeleted
Private Sub schedulerStorage1_AppointmentDependenciesChanged(ByVal sender As Object, ByVal e As PersistentObjectsEventArgs)
CommitTaskDependency()
End Sub
Private Sub schedulerStorage1_AppointmentDependenciesDeleted(ByVal sender As Object, ByVal e As PersistentObjectsEventArgs)
CommitTaskDependency()
End Sub
Private Sub schedulerStorage1_AppointmentDependenciesInserted(ByVal sender As Object, ByVal e As PersistentObjectsEventArgs)
CommitTaskDependency()
End Sub
Private Sub CommitTaskDependency()
taskDependenciesTableAdapter.Update(Me.gantTestDataSet.Tables("TaskDependencies"))
Me.gantTestDataSet.Tables("TaskDependencies").AcceptChanges()
End Sub
See Also