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

Dynamic table creation with GroupHeaders/Footers, Subtotals and totals

1 Answer 324 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
kenneyy kenn
Top achievements
Rank 1
kenneyy kenn asked on 22 Nov 2012, 09:44 AM
Hello,

As a feasibility study on whether the Telerik Reporting control is fit for our purpose, we're trying to create the above and have downloaded / tweaked some sample code from this forum but the final solution is not getting us where we want to be.

I want to add columns to a table object at runtime
  • the table will have
    • column headers
    • groups
      • each group will have a
        • group header
        • group footer and
        • a subtotals column (on a quantity column)

The core of the code is shown below

The group headers / footers are NOT displaying - once this is accomplished the rest should be easy 

Telerik gods we beg you, please tell us what we're doing wrong!!!

 

//DataSet passed in as parameter

 

foreach (DataColumn dc in reportDS.Tables[0].Columns)

{

 

//Add table column group

 

TableGroup tableGroup1 = new Telerik.Reporting.TableGroup();

tableGroup1.Sortings.Add(

 

new Sorting(grpTitle1, SortDirection.Asc));

tableGroup1.Name =

 

Group1";

 

//tableGroup1.Groupings.Add("1=1");

 

 

//tableGroup1.Groupings.Add(new Grouping());

tableGroup1.Groupings.Add(grpTitle1);

this.table1.ColumnGroups.Add(tableGroup1);

#region Grouping

 

 

if (!groupingAdded)

{

 

Group group = new Group();

Grouping groupExpression = new Grouping(grpTitle1);

group.Groupings.Add(groupExpression);

group.Sortings.Add(

 

new Telerik.Reporting.Sorting(grpTitle1, Telerik.Reporting.SortDirection.Asc));

group.GroupHeader =

 

new GroupHeaderSection();

group.GroupHeader.Height =

 

new Unit(10.0, UnitType.Mm);

group.GroupHeader.Style.BackgroundColor =

 

Color.LightSteelBlue;

Telerik.Reporting.

 

TextBox tbxGroupHdr = new Telerik.Reporting.TextBox();

tbxGroupHdr.Value =

 

"=" + grpTitle1;

tbxGroupHdr.Size =

 

new SizeU(new Unit(10, UnitType.Mm), new Unit(30.0, UnitType.Mm));

group.GroupHeader.Items.Add(tbxGroupHdr);

group.GroupFooter =

 

new GroupFooterSection();

group.GroupFooter.Height =

 

new Unit(10.0, UnitType.Mm);

group.GroupFooter.Style.BackgroundColor =

 

Color.LightYellow;

Telerik.Reporting.

 

TextBox tbxGroupFtr = new Telerik.Reporting.TextBox();

tbxGroupFtr.Value =

 

"Group Footer";

tbxGroupFtr.Size =

 

new SizeU(new Unit(10, UnitType.Mm), new Unit(30.0, UnitType.Mm));

group.GroupFooter.Items.Add(tbxGroupFtr);

 

this.table1.Report.Groups.Add(group);

groupingAdded =

 

true;

}

#endregion

 

 

//Add table body column

 

//this.table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Inch(1)));

txtColumnHdr =

 

new Telerik.Reporting.HtmlTextBox();

SetTextboxStyle(count, columnCount, dc.ColumnName, fntHdr,

 

TextBoxType.Group, ref txtColumnHdr);

tableGroup1.ReportItem = txtColumnHdr;

               

 

 

txtColumnBdy =

 

 

new Telerik.Reporting.HtmlTextBox();

SetTextboxStyle(count, columnCount, dc.ColumnName, fntBdy,

 

TextBoxType.Item, ref txtColumnBdy);

 

this.table1.Body.SetCellContent(0, i++, txtColumnBdy);

 

this.table1.Items.AddRange(new ReportItemBase[] { txtColumnHdr, txtColumnBdy });

count++;

}



1 Answer, 1 is accepted

Sort by
0
IvanY
Telerik team
answered on 27 Nov 2012, 12:21 PM
Hi Kenneyy,

As a best practice we can recommend you to use the designer to create the tables that later you are going to create programmatically. Once you have done this you can check the code behind file to see the code serialized. Additionally you can create your tables step by step and check the code after each step to see what is generated.

Regarding your issue - in general you have to create the parent group and add to it as child groups the header, footer and your main group and then add this parent group to the row groups of the table (the code that you have provided does not do that, or at least it does not contain such code). Therefore just create a simple Crosstab with the designer and add the respective group with header and footer; then check the designer.cs file to see the code generated.

Kind regards,
IvanY
the Telerik team

HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

Tags
General Discussions
Asked by
kenneyy kenn
Top achievements
Rank 1
Answers by
IvanY
Telerik team
Share this question
or