I'm trying to use the ultraganttviewcontrol with my database, but i'm not finding the correct way to bind the projects and task datasources. I already tried to bind my database to a ultragrid and that works fine. So my question is if you can point me in the right direction of an example with a database connection and what the best method is to do the databinding. I would prefer using entity framework if that is possible.
You can refer to this Databinding support for UltraGanttView online help document for binding projects and tasks to UltraGanttView.
Please go over this document and let me know if I may be of further assistance.
Sincerely,Sahaja KokkalagaddaAssociate Software Developer
Hello Sahaja Kokkalagadda,
Thanks for answering. I already found that document but it's not really useful if you use it with a database.
I tried it again now, but I still have problems.
First problem: I only get the unnassigned project and even tough the projectKey is different for tasks they are all shown on the ganttview.
This is my testing code for getting the data from the database.
private DataSet ds;
private SqlDataAdapter pda;
private SqlDataAdapter tda;
public DataSet GetProjectsDataSet(string ConnectionString)
SqlConnection conn = new SqlConnection(ConnectionString);
pda = new SqlDataAdapter();
SqlCommand cmdP = conn.CreateCommand();
cmdP.CommandText = "SELECT * FROM Project";
pda.SelectCommand = cmdP;
sqlCmdBuilderP = new SqlCommandBuilder(pda);
tda = new SqlDataAdapter();
SqlCommand cmdT = conn.CreateCommand();
cmdT.CommandText = "SELECT * FROM Task";
tda.SelectCommand = cmdT;
sqlCmdBuilderT = new SqlCommandBuilder(tda);
ds = new DataSet();
And this is my code for adding the data to the ganttview.
DataSet ds = GetProjectsDataSet(connString);
// Set the BindingContextControl property to reference this form
this.ultraCalendarInfo1.DataBindingsForTasks.BindingContextControl = this;
this.ultraCalendarInfo1.DataBindingsForProjects.BindingContextControl = this;
// Set the DataBinding members for Projects
this.ultraCalendarInfo1.DataBindingsForProjects.IdMember = "ProjectID";
this.ultraCalendarInfo1.DataBindingsForProjects.KeyMember = "ProjectKey";
this.ultraCalendarInfo1.DataBindingsForProjects.NameMember = "ProjectName";
this.ultraCalendarInfo1.DataBindingsForProjects.StartDateMember = "ProjectStartTime";
// Set the DataBinding members for Tasks
// Basic Task properties
this.ultraCalendarInfo1.DataBindingsForTasks.NameMember = "TaskName";
this.ultraCalendarInfo1.DataBindingsForTasks.DurationMember = "TaskDuration";
this.ultraCalendarInfo1.DataBindingsForTasks.StartDateTimeMember = "TaskStartTime";
this.ultraCalendarInfo1.DataBindingsForTasks.IdMember = "TaskID";
this.ultraCalendarInfo1.DataBindingsForTasks.ProjectKeyMember = "ProjectKey";
this.ultraCalendarInfo1.DataBindingsForTasks.ParentTaskIdMember = "ParentTaskID";
this.ultraCalendarInfo1.DataBindingsForTasks.ConstraintMember = "Constraint";
this.ultraCalendarInfo1.DataBindingsForTasks.PercentCompleteMember = "TaskPercentComplete";
// All other properties
this.ultraCalendarInfo1.DataBindingsForTasks.AllPropertiesMember = "AllProperties";
// Since we are showing a task that belongs to an explicitly defined
// project (i.e., not the UnassignedProject), assign that project to
// the control's Project property so the control knows to display that project.
this.ultraGanttView1.CalendarInfo = this.ultraCalendarInfo1;
this.ultraGanttView1.Project = this.ultraGanttView1.CalendarInfo.Projects;
For updating the data to the database I currently have a button on my form wich I press to call following code:
Here my database shedule:
CREATE TABLE [dbo].[Project] (
[ProjectID] UNIQUEIDENTIFIER CONSTRAINT [DF_Project_ProjectID] DEFAULT (newsequentialid()) NOT NULL,
[ProjectKey] NVARCHAR (MAX) NULL,
[ProjectName] NVARCHAR (MAX) NULL,
[ProjectStartTime] DATETIME NULL,
CONSTRAINT [PK_Project] PRIMARY KEY CLUSTERED ([ProjectID] ASC)
CREATE TABLE [dbo].[Task] (
[TaskID] UNIQUEIDENTIFIER CONSTRAINT [DF_Task_TaskID] DEFAULT (newsequentialid()) NOT NULL,
[ProjectKey] NVARCHAR (MAX) NULL,
[TaskName] NVARCHAR (MAX) NULL,
[TaskStartTime] DATETIME NULL,
[TaskDuration] NVARCHAR (MAX) NULL,
[ParentTaskID] NVARCHAR (MAX) NULL,
[Constraint] INT NULL,
[TaskPercentComplete] INT NULL,
[AllProperties] VARBINARY (MAX) NULL,
CONSTRAINT [PK_Task] PRIMARY KEY CLUSTERED ([TaskID] ASC),
CONSTRAINT [FK_Task_Task] FOREIGN KEY ([TaskID]) REFERENCES [dbo].[Task] ([TaskID])
I hope you can help me find my problem.
Second problem: When I have subtasks and remove the parenttask, the tasks don't get deleted as it should be. But I think this problem has something to do with the first problem so I think I need to solve the first problem first.
Many thanks in advance!
I have reviewed the code you posted here. The way projects and their tasks are binded to the CalenderInfo object looks fine to me but without debugging it is hard to identify why tasks with different project id are showing up.
I have attached a sample in which the GanttView is bound to a DataSet. Please review the code in it to verify if the parent and child tasks are added like shown in the sample. Also verify if the Project and Task tables are populated with all the expected values.
To further look into this issue we need a sample that can be used to debug locally. It will help if you can provide a small, isolated sample application that demonstrates the behavior you are seeing. This can be done by either making the sample that I provided more like your application or by isolating the behavior from your application by removing dependencies on any third parties or databases.
I will further look into this issue as soon as I hear back from you.
Thanks for the help!
I think my problem was this line:
And I needed to fill in the startdate of the projects, or it wouldn't find/add the projects.
But now I have 2 new questions:
First question: When I want to update the changed data to the database, is it possible to automatically update it? Now I'm doing it by doing:
tda.Update(ds.Tables["Tasks"]);// tda = taskDataAdapter
(For the ultragrid i'm using I also need to do it this way)
I added a column 'Color' in my database and want to show it in the ultraganttview so I added this line:
this.ultraGanttView1.CalendarInfo.CustomTaskColumns.Add("Color", typeof(String), false);
But it doesn't work, I always get 'System.NullReferenceException: 'Object reference not set to an instance of an object.''
And an additional question, is it possible to add color as a dropdown?
The data modified in Gantt View should be automatically updated in Database. Have you tested this behavior in the sample I attached previously?
To add a custom color column, you can refer to our online Gantt View Custom Columns sample.
It is possible to make the custom column as a dropdown by adding a ComboEditor to it. For example, you can write something like this to achieve it:
EditorWithCombo combo = new EditorWithCombo();
ValueList comboBinding = new ValueList(); for (int i = 0; i < 10; i++) comboBinding.ValueListItems.Add("Item " + i.ToString());
this.ganntView1.GridSettings.ColumnSettings[CustomColumn].Editor = combo; this.ganntView1.GridSettings.ColumnSettings[CustomColumn].ValueList = comboBinding;
Please let me know if I may be of further assistance.