Hello,
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.
Kind regards,
Robbe
Hello Rudy,
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; SqlCommandBuilder sqlCmdBuilderP; SqlCommandBuilder sqlCmdBuilderT; 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(); conn.Open(); pda.Fill(ds,"Projects"); tda.Fill(ds, "Tasks"); conn.Close(); return ds; }
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.SetDataBinding(ds, "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 this.ultraCalendarInfo1.DataBindingsForTasks.SetDataBinding(ds, "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; Debug.Print(this.ultraGanttView1.CalendarInfo.Projects[0].Key); this.ultraGanttView1.Project = this.ultraGanttView1.CalendarInfo.Projects[0];
For updating the data to the database I currently have a button on my form wich I press to call following code:
pda.Update(ds.Tables["Projects"]); tda.Update(ds.Tables["Tasks"]);
Here my database shedule:
For projects
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) );
For tasks:
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!
Hello Robbe,
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.
WinGanttViewBindToData1.zip
Thanks for the help!
I think my problem was this line:
ds.Relations.Add(ds.Tables["Projects"].Columns["ProjectKey"], ds.Tables["Tasks"].Columns["ProjectKey"]);
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)
Second question:
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?
Hello Sahaja,
I resolved my null pointer exception. When I added my calenderinfo in the designer (by using the properties) I got the exception. But in your project I never get the null pointer exception. So I don't really know why I can't do it with the designer but it is solved. Thank you for your help.
I have modified the attached sample to demonstrate how you can add a custom Color column to the GanttView and make it as a dropdown using a ComboEditor.
Please clarify the complete 17.1 build number so I can test it with the exact version to see if I can reproduce the null pointer exception that you were mentioning about.
Like I mentioned before, the data modified in Gantt View should be automatically updated in Database. The underlying Database should not matter to observe this behavior.
Let me know if you have any questions.
3782.WinGanttViewBindToData1.zip
***BUMP***
I already had found that example but it doesn't work for adding the custom column, I have a null pointer exception (see my added code).
Also when I change the way of populating the dataset in your example to getting it from the database, it still doesn't update my database.
I've added a small example of my code, but you will still need a database. I'm using version 17.1.
ProjectPlanning.zip
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.