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,
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.
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
***BUMP***
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
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.