Show custom fields in gantt chart view

Hi,


I tried to follow “Configure Gantt Chart View by Showing Selected Custom Fields” article and show the custom fields created programatically in the default view.


TableField billablefld = new TableField();
billablefld.Field = Field.TaskFlag1;
billablefld.Width = 20;
billablefld.AlignData = System.Drawing.StringAlignment.Center;
billablefld.AlignTitle = System.Drawing.StringAlignment.Center;
billablefld.Title = “Billable”;
Aspose.Tasks.Table table = pj.Tables.ToList()[0];
table.TableFields.Insert(3, billablefld);

The above was written based on the sample code in the article. But I get an error at the bolded line as there are no tables in the project class. Kindly help in showing custom columns in the default view of gantt chart.

Regards,

Hi Purnima,


You need to use an empty template project (MPP created by MSP) for initiating the project object. You may also set MPPSaveOptions.WriteViewData flag to true. Please give a try to the following sample code and share the feedback.



Project proj = new Project(@“Blank2010.mpp”);


TableField billablefld = new TableField();

billablefld.Field = Field.TaskFlag1;

billablefld.Width = 20;

billablefld.AlignData = System.Drawing.StringAlignment.Center;

billablefld.AlignTitle = System.Drawing.StringAlignment.Center;

billablefld.Title = “Billable”;

Aspose.Tasks.Table table = proj.Tables.ToList()[0];

table.TableFields.Insert(3, billablefld);

MPPSaveOptions options = new MPPSaveOptions();

options.WriteViewData = true;


proj.Save(“Output.mpp”, options);