Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1370
How to use GanttView with DataBinding ? Sample throws an exception
posted

Hi

I read the sample and did the same but an error occurs on the line :

this.ugvProjects.CalendarInfo = this.uciGantt;

With NullreferenceException


Here my code :

ugvProjects is my UltraGanttView Control on winform
uciGantt is my ultracalendarInfo control on winform

private void LoadGantt()
{
DataSet ds = new DataSet();

ds.Tables.Add("PROJECTS");
ds.Tables[0].Columns.Add("ProjectID");
ds.Tables[0].Columns.Add("ProjectKey");
ds.Tables[0].Columns.Add("ProjectName");
ds.Tables[0].Columns.Add("ProjectStartTime" ,typeof(DateTime));

ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["ProjectID"] = Guid.NewGuid();
ds.Tables[0].Rows[ds.Tables[0].Rows.Count-1]["ProjectKey"]="Key1";
ds.Tables[0].Rows[ds.Tables[0].Rows.Count-1]["ProjectName"]="Key 1 project name";
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["ProjectStartTime"] = DateTime.Now.ToShortDateString();

ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["ProjectID"] = Guid.NewGuid();
ds.Tables[0].Rows[ds.Tables[0].Rows.Count-1]["ProjectKey"]="Key2";
ds.Tables[0].Rows[ds.Tables[0].Rows.Count-1]["ProjectName"]="Key 2 project name";
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["ProjectStartTime"] = DateTime.Now.ToShortDateString();


ds.Tables.Add("TASKS");
ds.Tables[1].Columns.Add("TaskID");
ds.Tables[1].Columns.Add("ProjectKey");
ds.Tables[1].Columns.Add("TaskName");
ds.Tables[1].Columns.Add("TaskStartTime", typeof(DateTime));
ds.Tables[1].Columns.Add("TaskDuration");
ds.Tables[1].Columns.Add("ParentTaskID");
ds.Tables[1].Columns.Add("TaskConstraint");
ds.Tables[1].Columns.Add("TaskPercentComplete");
ds.Tables[1].Columns.Add("AllProperties");

ds.Tables[1].Rows.Add(ds.Tables[1].NewRow());
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskID"] = Guid.NewGuid();
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["ProjectKey"] = "Key1";
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskName"] = "task 1 name";
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskStartTime"] = DateTime.Now.ToShortDateString();
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskDuration"] = 60;
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["ParentTaskID"] = ds.Tables[0].Rows[0]["ProjectID"];
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskConstraint"] = "StartNoEarlierThan";
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskPercentComplete"] = null;
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["AllProperties"] = null;


ds.Tables[1].Rows.Add(ds.Tables[1].NewRow());
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskID"] = Guid.NewGuid();
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["ProjectKey"] = "Key1";
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskName"] = "task 2 name";
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskStartTime"] = DateTime.Now.AddDays(60).ToShortDateString();
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskDuration"] = 40;
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["ParentTaskID"] = ds.Tables[0].Rows[0]["ProjectID"];
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskConstraint"] = "StartNoEarlierThan";
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskPercentComplete"] = null;
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["AllProperties"] = null;


ds.Tables[1].Rows.Add(ds.Tables[1].NewRow());
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskID"] = Guid.NewGuid();
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["ProjectKey"] = "Key2";
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskName"] = "task 3 name";
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskStartTime"] = DateTime.Now.AddDays(10).ToShortDateString();
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskDuration"] = 15;
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["ParentTaskID"] = ds.Tables[0].Rows[1]["ProjectID"];
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskConstraint"] = "StartNoEarlierThan";
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["TaskPercentComplete"] = null;
ds.Tables[1].Rows[ds.Tables[1].Rows.Count - 1]["AllProperties"] = null;


this.uciGantt.DataBindingsForTasks.BindingContextControl = this;
this.uciGantt.DataBindingsForProjects.BindingContextControl = this;

this.uciGantt.DataBindingsForProjects.SetDataBinding(ds, "Projects");
this.uciGantt.DataBindingsForProjects.IdMember = "ProjectID";
this.uciGantt.DataBindingsForProjects.KeyMember = "ProjectKey";
this.uciGantt.DataBindingsForProjects.NameMember = "ProjectName";
this.uciGantt.DataBindingsForProjects.StartDateMember = "ProjectStartTime";

this.uciGantt.DataBindingsForTasks.SetDataBinding(ds, "Tasks");
this.uciGantt.DataBindingsForTasks.NameMember = "TaskName";
this.uciGantt.DataBindingsForTasks.DurationMember = "TaskDuration";
this.uciGantt.DataBindingsForTasks.StartDateTimeMember = "TaskStartTime";
this.uciGantt.DataBindingsForTasks.IdMember = "TaskID";
this.uciGantt.DataBindingsForTasks.ProjectKeyMember = "ProjectKey";
this.uciGantt.DataBindingsForTasks.ParentTaskIdMember = "ParentTaskID";
this.uciGantt.DataBindingsForTasks.ConstraintMember = "TaskConstraint";
this.uciGantt.DataBindingsForTasks.PercentCompleteMember = "TaskPercentComplete";
this.uciGantt.DataBindingsForTasks.AllPropertiesMember = "AllProperties";


this.ugvProjects.CalendarInfo = this.uciGantt;
this.ugvProjects.Project = this.ugvProjects.CalendarInfo.Projects[1];


}

Thank you very much.