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

CrossTab - dynamic columns

1 Answer 351 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 02 Aug 2011, 05:26 PM
I have a crosstab in my report that needs dynamic columns so I am building the groups/rows/columns in the NeedDataSource method.  To get me started, I set up the crosstab in the designer with 2 columns and bind it to a datatable.  The Crosstab displays the data correctly.  Then I reviewed the designer code, and add the groups/rows/columns exactly how it is done in the designer.  Note:  at this point, I am still just adding the 2 columns, so the crosstab should be exactly the same as when built in the designer.  But when I bind the crosstab to the same datatable, it throws an "Index was out of range...." exception.  Since the groups/rows/columns should be the same as when built in the designer, I could be missing a step prior to adding the groups/rows/columns.  Currently, I am clearing all RowGroups, ColumnGroups, Body.Columns, Body.Rows, and Items from the crosstab.  (then adding the rows/columns/groups)  Is there anything else I need to do?  Do you have any other ideas on what might cause the "Index was out of range..." exception?  Here is my code:
crosstab1.RowGroups.Clear();
crosstab1.ColumnGroups.Clear();
crosstab1.Body.Columns.Clear();
crosstab1.Body.Rows.Clear();
crosstab1.Items.Clear();
crosstab1.Corner.ClearCellContent();
 
crosstab1.Body.Columns.Add(new TableBodyColumn(new Unit(2D, UnitType.Inch)));
crosstab1.Body.Columns.Add(new TableBodyColumn(new Unit(2D, UnitType.Inch)));
crosstab1.Body.Rows.Add(new TableBodyRow(new Unit(0.26D, UnitType.Inch)));
 
TextBox txtBx = new TextBox() { Size = new SizeU(new Unit(2D, UnitType.Inch), new Unit(0.26D, UnitType.Inch)), Value = "=Fields.Jun2011" };
crosstab1.Items.Add(txtBx);
crosstab1.Body.SetCellContent(0, 0, txtBx);
 
txtBx = new TextBox() { Size = new SizeU(new Unit(2D, UnitType.Inch), new Unit(0.26D, UnitType.Inch)), Value = "=Fields.Jul2011" };
crosstab1.Items.Add(txtBx);
crosstab1.Body.SetCellContent(0, 1, txtBx);
 
TableGroup group1 = new TableGroup();
group1.Groupings.Add(new Telerik.Reporting.Data.Grouping("=\'ColumnGroup\'"));
txtBx = new TextBox() { Size = new SizeU(new Unit(2D, UnitType.Inch), new Unit(0.26D, UnitType.Inch)), Value = "June 2011" };
crosstab1.Items.Add(txtBx);
group1.ReportItem = txtBx;
 
TableGroup group2 = new TableGroup();
txtBx = new TextBox() { Size = new SizeU(new Unit(2D, UnitType.Inch), new Unit(0.26D, UnitType.Inch)), Value = "July 2011" };
crosstab1.Items.Add(txtBx);
group2.ReportItem = txtBx;
 
 
crosstab1.ColumnGroups.Add(group1);
crosstab1.ColumnGroups.Add(group2);
 
txtBx = new TextBox() { Size = new SizeU(new Unit(2D, UnitType.Inch), new Unit(0.26D, UnitType.Inch)), Value = "Project Name" };
crosstab1.Items.Add(txtBx);
crosstab1.Corner.SetCellContent(0, 0, txtBx);
 
txtBx = new TextBox() { Size = new SizeU(new Unit(2D, UnitType.Inch), new Unit(0.26D, UnitType.Inch)), Value = "Type Of Financial" };
crosstab1.Items.Add(txtBx);
crosstab1.Corner.SetCellContent(0, 1, txtBx);
 
 
TableGroup group4 = new TableGroup();
group4.Groupings.Add(new Telerik.Reporting.Data.Grouping("=Fields.TypeOfFinancial"));
txtBx = new TextBox() { Size = new SizeU(new Unit(2D, UnitType.Inch), new Unit(0.26D, UnitType.Inch)), Value = "=Fields.TypeOfFinancial" };
crosstab1.Items.Add(txtBx);
group4.ReportItem = txtBx;
group4.Sortings.Add(new Telerik.Reporting.Data.Sorting("=Fields.TypeOfFinancial", Telerik.Reporting.Data.SortDirection.Asc));
 
 
TableGroup group3 = new TableGroup();
group3.ChildGroups.Add(group4);
group3.Groupings.Add(new Telerik.Reporting.Data.Grouping("=Fields.ProjectName"));
txtBx = new TextBox() { Size = new SizeU(new Unit(2D, UnitType.Inch), new Unit(0.26D, UnitType.Inch)), Value = "=Fields.ProjectName" };
crosstab1.Items.Add(txtBx);
group3.ReportItem = txtBx;
 
crosstab1.RowGroups.Add(group3);
 
crosstab1.DataSource = ConstructDataTable();

1 Answer, 1 is accepted

Sort by
0
Justin Lee
Top achievements
Rank 1
answered on 02 Aug 2011, 05:50 PM
Sorry for the spam -- I figured it out after posting.  Since the Rows and RowGroups are not dynamic, I removed the code that cleared and added them, and the report works now (although I'm still not sure why it wasn't working before).  Now only columns and column groups are added in code.

Thanks,
Justin
Tags
General Discussions
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Justin Lee
Top achievements
Rank 1
Share this question
or