Skip to main content Skip to footer

Data Binding in GanttView for WinForms

ComponentOne Studio GanttView for WinForms delivers a Microsoft Project-like user experience for project management. The control provides both a tabular data grid and a graphical chart to help schedule, coordinate and track specific tasks in a project. With the release of 2015 V2, we've extended the features of GanttView in terms of Data Binding.

Configure a data source and synchronize data with the GanttView control.

GV This blog provides step-by-step instructions for binding GanttView to a data source at runtime.

Configuring the Data Source

You can use standard ADO.NET data binding to bind GanttView to an existing database. First, configure your data source for the purpose.


OleDbConnection conn;  
OleDbDataAdapter TasksAdapter;  
OleDbDataAdapter ResourcesAdapter;  
OleDbDataAdapter CalendarsAdapter;  
OleDbDataAdapter PropertiesAdapter;  
// Configuring the DataSource  
conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\C1NWind.mdb");  
CalendarsAdapter = new OleDbDataAdapter("select * from Calendars", conn);  
CalendarsAdapter.Fill(table_Calendars);  
PropertiesAdapter = new OleDbDataAdapter("select * from Properties", conn);  
PropertiesAdapter.Fill(table_Properties);  
ResourcesAdapter = new OleDbDataAdapter("select * from Resources", conn);  
ResourcesAdapter.Fill(table_Resources);  
TasksAdapter = new OleDbDataAdapter("select * from Tasks", conn);  
TasksAdapter.Fill(table_Tasks);  

Setting Up the C1GanttViewStorage Component and Data Mappings

The C1GanttViewStorage component handles all data operations for the C1GanttView control and contains specific data storages and properties which are used for binding corresponding collections to the data.

DataStorages

The C1GanttViewStorage component contains specific data storages for Calendars, Properties, Resources and Tasks, which work on the data layer to provide data to the application.

Data Storage

Description

CalendarStorage

Storage for CustomCalendar objects.

PropertyStorage

Storage for some object properties.

ResourceStorage

Storage for resource objects.

TasksStorage

Storage for task objects.

When you provide data, be sure to specify mappings between data fields in the datasource and their interpretation in the storage. These settings bind the GanttView control to the data source and enhance the visual appearance of the control.

CalendarStorage Mappings

Calendar


//Setting Mappings in CalendarStorage  
this.c1GanttView1.DataStorage.CalendarStorage.Mappings.CalendarID.MappingName = "CalendarID";  
this.c1GanttView1.DataStorage.CalendarStorage.Mappings.Data.MappingName = "Data";  
this.c1GanttView1.DataStorage.CalendarStorage.Mappings.IdMapping.MappingName = "Id";  
this.c1GanttView1.DataStorage.CalendarStorage.Mappings.Name.MappingName = "Name";  

PropertyStorage Mappings

Property


//Setting Mappings in PropertyStorage  
this.c1GanttView1.DataStorage.PropertyStorage.Key.MappingName = "Key";  
this.c1GanttView1.DataStorage.PropertyStorage.Value.MappingName = "Value";  

ResourceStorage Mappings

Resource


//Setting Mappings in ResourceStorage  
this.c1GanttView1.DataStorage.ResourceStorage.Mappings.Cost.MappingName = "Cost";  
this.c1GanttView1.DataStorage.ResourceStorage.Mappings.IdMapping.MappingName = "Id";  
this.c1GanttView1.DataStorage.ResourceStorage.Mappings.Name.MappingName = "Name";  
this.c1GanttView1.DataStorage.ResourceStorage.Mappings.Notes.MappingName = "Notes";  
this.c1GanttView1.DataStorage.ResourceStorage.Mappings.ResourceID.MappingName = "ResourceID";  
this.c1GanttView1.DataStorage.ResourceStorage.Mappings.ResourceType.MappingName = "ResourceType";  
this.c1GanttView1.DataStorage.ResourceStorage.Mappings.UnitOfMeasure.MappingName = "UnitOfMeasure";  

TasksStorage Mappings

Tasks


//Setting Mappings in TasksStorage  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.CalendarID.MappingName = "CalendarID";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.ConstraintDate.MappingName = "ConstraintDate";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.ConstraintType.MappingName = "ConstraintType";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.CustomFields.MappingName = "CustomFields";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.Deadline.MappingName = "Deadline";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.Duration.MappingName = "Duration";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.DurationUnits.MappingName = "DurationUnits";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.Finish.MappingName = "Finish";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.HideBar.MappingName = "HideBar";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.IdMapping.MappingName = "Id";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.Initialized.MappingName = "Initialized";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.Mode.MappingName = "Mode";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.Name.MappingName = "Name";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.NextID.MappingName = "NextID";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.Notes.MappingName = "Notes";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.OutlineParentID.MappingName = "OutlineParentID";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.PercentComplete.MappingName = "PercentComplete";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.Predecessors.MappingName = "Predecessors";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.Resources.MappingName = "Resources";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.Start.MappingName = "Start";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.Summary.MappingName = "Summary";  
this.c1GanttView1.DataStorage.TasksStorage.Mappings.TaskID.MappingName = "TaskID";  

Now that all the mappings have been set, you can set DataSource for all the storages.


//Binding C1GanttView to the DataSource  
c1GanttView1.DataStorage.CalendarStorage.DataSource = table_Calendars;  
c1GanttView1.DataStorage.PropertyStorage.DataSource = table_Properties;  
c1GanttView1.DataStorage.ResourceStorage.DataSource = table_Resources;  
c1GanttView1.DataStorage.TasksStorage.DataSource = table_Tasks;  

Setting DefaultWorkingTimes and the TimeScale

The next step is to set the default day working start/end times and the TimeScale. TimeScale is basically used for setting the minimum and maximum date/time and specifying the visible tiers.


//Setting DefaultWorkingTimes  
this.c1GanttView1.DefaultWorkingTimes.Interval_1.Empty = false;  
this.c1GanttView1.DefaultWorkingTimes.Interval_1.From = new System.DateTime(1, 1, 1, 9, 0, 0, 0);  
this.c1GanttView1.DefaultWorkingTimes.Interval_1.To = new System.DateTime(1, 1, 1, 13, 0, 0, 0);  
this.c1GanttView1.DefaultWorkingTimes.Interval_2.Empty = false;  
this.c1GanttView1.DefaultWorkingTimes.Interval_2.From = new System.DateTime(1, 1, 1, 14, 0, 0, 0);  
this.c1GanttView1.DefaultWorkingTimes.Interval_2.To = new System.DateTime(1, 1, 1, 18, 0, 0, 0);  

//Setting the TimeScale  
this.c1GanttView1.Timescale.BottomTier.Align = C1.Win.C1GanttView.ScaleLabelAlignment.Center;  
this.c1GanttView1.Timescale.BottomTier.Format = "w";  
this.c1GanttView1.Timescale.BottomTier.Visible = true;  
this.c1GanttView1.Timescale.BottomTier.UseFiscalYear = true;  
this.c1GanttView1.Timescale.BottomTier.Units = TimescaleUnits.Days;  
this.c1GanttView1.Timescale.BottomTier.Count = 1;  
this.c1GanttView1.Timescale.MiddleTier.Format = "nnnn d";  
this.c1GanttView1.Timescale.MiddleTier.Units = C1.Win.C1GanttView.TimescaleUnits.Weeks;  
this.c1GanttView1.Timescale.MiddleTier.Visible = true;  
this.c1GanttView1.Timescale.MiddleTier.Count = 1;  

Adding Resources and TaskPropertyColumns

A resource is a keyword or a phrase defining a source of support for a particular task. Resources, stored in the C1GanttView.Resources Collection, are optional, and a task can have one or more resources assigned to it. For more information on Assigning Resources to a Task, take a look at the documentation. The last step is to add TaskPropertyColumns in the GanttView. These attributes appear in the columns of the C1GanttView control. The default visible columns are Task Mode and Task Name. However, you can also add Custom Columns if needed.

Working Sample

Download the sample implementing all of the above discussed steps: Data Binding in C1GanttView

Try V2 Today!

MESCIUS inc.

comments powered by Disqus