This is a migrated thread and some comments may be shown as answers.

Dynamic Table Columns

5 Answers 1055 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ryan
Top achievements
Rank 1
Ryan asked on 01 Feb 2011, 07:21 PM
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.

[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) +5563


Below 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!

5 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 02 Feb 2011, 01:00 PM
Hello Ryan,

Looking at the stack trace, this error can occur if you have a row/column group with Size=0. I've attached a sample project that shows you how to create table dynamically correctly.
Give it a spin and let us know how it goes.

All the best,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Travis
Top achievements
Rank 1
answered on 19 Apr 2011, 06:27 PM

I have a table with four columns set in the designer and I want to add a dynamic number of columns at the end of the table.  Is this possible? I'm setting my datasource via the designer as well.  I tried using the above code but am getting the same error as above.  The column I'm trying to add will be the 5th column in the table.  Here's my code:

private void table1_ItemDataBinding(object sender, EventArgs e)
       {
           TableGroup tableGroupColumn = new TableGroup();
           table1.ColumnGroups.Add(tableGroupColumn);
           table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Inch(1)));
           Telerik.Reporting.HtmlTextBox textboxGroup = new Telerik.Reporting.HtmlTextBox();
           textboxGroup.Style.BorderColor.Default = Color.Black;
           textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
           textboxGroup.Value = "My Dynamic Column";
           textboxGroup.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
           tableGroupColumn.ReportItem = textboxGroup;
           Telerik.Reporting.HtmlTextBox textBoxTable = new Telerik.Reporting.HtmlTextBox();
           textBoxTable.Style.BorderColor.Default = Color.Black;
           textBoxTable.Style.BorderStyle.Default = BorderType.Solid;
           textBoxTable.Value = "=\"test value\"";
           textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
           this.table1.Body.SetCellContent(0, 4, textBoxTable);
           this.table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });
       }
0
Steve
Telerik team
answered on 22 Apr 2011, 04:03 PM
Hi Travis,

It would be best to open a support ticket and attach a runnable sample project that exhibits the problem.

Best wishes,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Andrey
Top achievements
Rank 1
answered on 29 Jun 2012, 08:02 AM
Is there a solution to the problem described in this thread?
0
Benin
Top achievements
Rank 1
answered on 13 Apr 2013, 05:30 PM
This sample code is no longer working for a webapplication or website project. Can you please provide a fix?
Tags
General Discussions
Asked by
Ryan
Top achievements
Rank 1
Answers by
Steve
Telerik team
Travis
Top achievements
Rank 1
Andrey
Top achievements
Rank 1
Benin
Top achievements
Rank 1
Share this question
or