Data binding refers to the process of binding a data provider to a data consumer in a synchronized manner. You can bind GanttView control to different .NET data sources such as DataTable, DataView and DataSet.
The following image showcases the GanttView control bound to a data source.
The following topic explains step-by-step procedure for binding the GanttView control to a data source. This example uses a sample database file, Nwind.mdb, as the data source for binding.
The Nwind.mdb database file is by default kept in the installed folder at the following location on your system.
Documents\ComponentOne Samples\Common\Nwind.mdb
Complete the following steps to store data in your dataset and retrieve the same to display various project related attributes in GanttView.
C# |
Copy Code
|
---|---|
using C1.GanttView; using DataBinding.C1NWindDataSetTableAdapters; |
C# |
Copy Code
|
---|---|
private C1NWindDataSet c1NwindDataSet1 = new C1NWindDataSet(); private TasksTableAdapter tasksTableAdapter = new TasksTableAdapter(); private CalendarsTableAdapter calendarsTableAdapter = new CalendarsTableAdapter(); private ResourcesTableAdapter resourcesTableAdapter = new ResourcesTableAdapter(); private PropertiesTableAdapter propertiesTableAdapter = new PropertiesTableAdapter(); |
C# |
Copy Code
|
---|---|
this.tasksTableAdapter.Fill(c1NwindDataSet1.Tasks); this.resourcesTableAdapter.Fill(c1NwindDataSet1.Resources); this.propertiesTableAdapter.Fill(c1NwindDataSet1.Properties); this.calendarsTableAdapter.Fill(c1NwindDataSet1.Calendars); |
C# |
Copy Code
|
---|---|
gv.Loaded+=gv_Loaded; |
C# |
Copy Code
|
---|---|
private void gv_Loaded(object sender, RoutedEventArgs e) { C1GanttViewStorage storage = gv.DataStorage; storage.CalendarStorage.Mappings.CalendarID.MappingName = "CalendarID"; storage.CalendarStorage.Mappings.CalendarID.MappingName = "CalendarID"; storage.CalendarStorage.Mappings.Data.MappingName = "Data"; storage.CalendarStorage.Mappings.IdMapping.MappingName = "Id"; storage.CalendarStorage.Mappings.Name.MappingName = "Name"; storage.CalendarStorage.DataMember = "Calendars"; storage.CalendarStorage.DataSource = this.c1NwindDataSet1; storage.PropertyStorage.Key.MappingName = "Key"; storage.PropertyStorage.Value.MappingName = "Value"; storage.PropertyStorage.DataMember = "Properties"; storage.PropertyStorage.DataSource = this.c1NwindDataSet1; storage.ResourceStorage.Mappings.Cost.MappingName = "Cost"; storage.ResourceStorage.Mappings.IdMapping.MappingName = "Id"; storage.ResourceStorage.Mappings.Name.MappingName = "Name"; storage.ResourceStorage.Mappings.Notes.MappingName = "Notes"; storage.ResourceStorage.Mappings.ResourceID.MappingName = "ResourceID"; storage.ResourceStorage.Mappings.ResourceType.MappingName = "ResourceType"; storage.ResourceStorage.Mappings.UnitOfMeasure.MappingName = "UnitOfMeasure"; storage.ResourceStorage.DataMember = "Resources"; storage.ResourceStorage.DataSource = this.c1NwindDataSet1; storage.TasksStorage.Mappings.CalendarID.MappingName = "CalendarID"; storage.TasksStorage.Mappings.ConstraintDate.MappingName = "ConstraintDate"; storage.TasksStorage.Mappings.ConstraintType.MappingName = "ConstraintType"; storage.TasksStorage.Mappings.CustomFields.MappingName = "CustomFields"; storage.TasksStorage.Mappings.Deadline.MappingName = "Deadline"; storage.TasksStorage.Mappings.Duration.MappingName = "Duration"; storage.TasksStorage.Mappings.DurationUnits.MappingName = "DurationUnits"; storage.TasksStorage.Mappings.Finish.MappingName = "Finish"; storage.TasksStorage.Mappings.HideBar.MappingName = "HideBar"; storage.TasksStorage.Mappings.IdMapping.MappingName = "Id"; storage.TasksStorage.Mappings.Initialized.MappingName = "Initialized"; storage.TasksStorage.Mappings.Mode.MappingName = "Mode"; storage.TasksStorage.Mappings.Name.MappingName = "Name"; storage.TasksStorage.Mappings.NextID.MappingName = "NextID"; storage.TasksStorage.Mappings.Notes.MappingName = "Notes"; storage.TasksStorage.Mappings.Parts.MappingName = "Parts"; storage.TasksStorage.Mappings.PercentComplete.MappingName = "PercentComplete"; storage.TasksStorage.Mappings.Predecessors.MappingName = "Predecessors"; storage.TasksStorage.Mappings.Resources.MappingName = "Resources"; storage.TasksStorage.Mappings.Start.MappingName = "Start"; storage.TasksStorage.Mappings.TaskID.MappingName = "TaskID"; storage.TasksStorage.DataMember = "Tasks"; storage.TasksStorage.DataSource = this.c1NwindDataSet1; } |
C# |
Copy Code
|
---|---|
private void SaveData() { try { this.c1NwindDataSet1.HasChanges(); this.tasksTableAdapter.Update(this.c1NwindDataSet1.Tasks); this.resourcesTableAdapter.Update(this.c1NwindDataSet1.Resources); this.propertiesTableAdapter.Update(this.c1NwindDataSet1.Properties); this.calendarsTableAdapter.Update(this.c1NwindDataSet1.Calendars); this.c1NwindDataSet1.AcceptChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } |
C# |
Copy Code
|
---|---|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { SaveData(); } |
Run the application and notice that the GanttView gets bound to the tables in the NwindDataSet.