This question is locked. New answers and comments are not allowed.
I have a report with a table in it. The table has four columns I know at design time, but there are a unknown number of dynamic columns that I want to display at run time to the right of the four design time/static columns. Basically I am trying to replicate a Gantt chart and the first four columns are task names and key dates and the dynamic columns are the days I am going to eventually fill in with a background color if the task lands on the dynamic column representing the day.
I have found a couple samples in the forums for creating dynamic columns, but in all of the examples I get the following exception when I try to apply it to my code.
Below is report code that is generating the above error.
If anyone can provide a better example of how to dynamically add columns to a table that already has columns that would be great!
I have found a couple samples in the forums for creating dynamic columns, but in all of the examples I get the following exception when I try to apply it to my code.
[NullReferenceException: Object reference not set to an instance of an object.] Telerik.Reporting.Processing.Table.CalculateColumns() +328 Telerik.Reporting.Processing.Table.Measure(MeasureDirection dir, Graphics graphics) +786 Telerik.Reporting.Processing.ProcessingElement.MeasureElement(MeasureDirection dir, Graphics graphics) +181 Telerik.Reporting.Processing.ProcessingElement.Measure(MeasureDirection dir, Graphics graphics) +1509 Telerik.Reporting.Processing.ReportSectionBase.Measure(MeasureDirection dir, Graphics graphics) +48 Telerik.Reporting.Processing.ProcessingElement.MeasureElement(MeasureDirection dir, Graphics graphics) +181 Telerik.Reporting.Processing.Group.MeasureElement(MeasureDirection dir, Graphics graphics) +286 Telerik.Reporting.Processing.Report.MeasureElement(MeasureDirection dir, Graphics graphics) +471 Telerik.Reporting.Processing.Report.MeasureElement(ProcessingElement elementToMeasure) +220 Telerik.Reporting.Processing.Report.OnItemProcessed() +79 Telerik.Reporting.Processing.ReportItemBase.Process(DataMember data) +823 Telerik.Reporting.Processing.Report.Process(DataMember data, DataItemState state, Boolean interactivityEnabled, Boolean documentMapEnabled) +124 Telerik.Reporting.Processing.ReportProcessor.ProcessReport(IReportDocument reportDocument, IDictionary processingContext) +1313 Telerik.Reporting.Processing.ReportProcessor.RenderReport(String format, IReportDocument reportDocument, Hashtable deviceInfo, Hashtable renderingContext, CreateStream createStreamCallback) +579 Telerik.Reporting.Processing.ReportProcessor.RenderReportStateless(String format, IReportDocument reportDocument, Hashtable deviceInfo, Hashtable renderingContext, CreateStream createStreamCallback) +94 Telerik.Reporting.Processing.ReportProcessor.RenderReport(String format, IReportDocument reportDocument, Hashtable deviceInfo) +195 TaskReportPage.ExportToPDF(Report reportToExport) in c:\SourceControl\Phenomblue\Websites\WorkamajigAPI\Website\TaskReportPage.aspx.cs:105 TaskReportPage.btnGenerateGanttReport_Click(Object sender, EventArgs e) in c:\SourceControl\Phenomblue\Websites\WorkamajigAPI\Website\TaskReportPage.aspx.cs:99 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563Below is report code that is generating the above error.
namespace SOW.Reports{ using System; using System.ComponentModel; using System.Drawing; using System.Linq; using System.Windows.Forms; using Telerik.Reporting; using Telerik.Reporting.Drawing; using SOW.DataAccess; public partial class GanttReport : Telerik.Reporting.Report { SOWEntities sowContext = null; public GanttReport(int projectKey) { InitializeComponent(); sowContext = new SOWEntities(); vListing_Project project = sowContext.vListing_Project.FirstOrDefault(x => x.ProjectKey == projectKey); /******************** Task Report **********************/ var tasks = (from task in sowContext.pvTaskReports where task.ProjectKey == projectKey select new { task.Task_Level, task.Task_Name, task.Task_ID, task.Task_Days, task.Plan_Start_Date, task.Plan_Completion_Date, task.Track_Schedules, task.Task_Line_Number, task.Task_Type }).ToList(); tblTaskDetails.DataSource = tasks; } private void tblTaskDetails_ItemDataBinding(object sender, EventArgs e) { for (int i = 0; i < 10; i++) { TableGroup tableGroupColumn = new TableGroup(); tblTaskDetails.ColumnGroups.Add(tableGroupColumn); tblTaskDetails.Body.Columns.Add(new TableBodyColumn(Unit.Inch(.2))); Telerik.Reporting.TextBox textBoxGroup = new Telerik.Reporting.TextBox(); textBoxGroup.Value = "x" + i.ToString(); textBoxGroup.Size = new SizeU(Unit.Inch(.2), Unit.Inch(.2)); tableGroupColumn.ReportItem = textBoxGroup; Telerik.Reporting.TextBox textBoxTable = new Telerik.Reporting.TextBox(); textBoxTable.Value = ""; textBoxTable.Size = new SizeU(Unit.Inch(.2), Unit.Inch(.2)); tblTaskDetails.Body.SetCellContent(0, i++, textBoxTable); tblTaskDetails.Items.AddRange(new ReportItemBase[] { textBoxTable, textBoxGroup }); } } }}If anyone can provide a better example of how to dynamically add columns to a table that already has columns that would be great!