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

Table : TableBody : TableCellContainer: acces to modify by row & column

1 Answer 117 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Grégory
Top achievements
Rank 1
Grégory asked on 08 Aug 2013, 10:43 AM

Hello,

I'm updating a telerik TableCell with a C# data array (double[][]), and by now I'm updating the cells in the table by cell (for each cell in tablecell).

I would like to do on of this other options:

1. access a range of a row (subset) and set it with a list or array of the same length
2. access a row and set to a list or array.
3. access each cell element by asking for it by row & col in the table and set the value on the element
       
Is there any possibilities?

Thanks.

1 Answer, 1 is accepted

Sort by
0
IvanY
Telerik team
answered on 13 Aug 2013, 08:34 AM
Hi Grégory,

Up to your question - you will have to access each cell one by one. If you have a list with the same length you can just iterate through it and set each cell with the respective value from the list. For more information on how tables work please have a look at the description below:

The best option to learn how to create such tables programmatically would be to have a look at the InitializeComponent(). I will try here to explain the basics, but you will still have to play a little with the generated code so that you can achieve your specific task.

This is how you can add static columns (and rows, respectively):
this.crosstab1.Body.Columns.Add(new TableBodyColumn(Unit.Inch(1.15D)));

Each table and crosstab need at least a single static row and column, otherwise an exception will be thrown.

This is how you create a table group. A table group can span multiple columns or rows at runtime (it is not static):
tableGroup1.Groupings.AddRange(new Grouping[] { new Grouping("=Fields.City") });<br>tableGroup1.Name = "City1";<br>tableGroup1.ReportItem = this.textBox1;<br>tableGroup1.Sortings.AddRange(new Sorting[] { new Sorting("=Fields.City", SortDirection.Asc) });

Once you have created the table group you will have to add it to the respective row or column group in your crosstab. This is the code:
this.crosstab1.RowGroups.Add(tableGroup2);

This sets the content of the corner of the crosstab:
this.crosstab1.Corner.SetCellContent(0, 0, this.textBox3);

This sets a selected cell content:
this.crosstab1.Body.SetCellContent(0, 0, this.textBox4);

You will have to add all items to the crosstab regardless of the fact that you have already added them to a table group or a cell:
this.crosstab1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { this.textBox1, this.textBox2, this.textBox3, this.textBox4 });

The below snippet sets some easy to understand properties, like size, data source, etc:
this.crosstab1.DataSource = this.sqlDataSource1;<br>this.crosstab1.Location = new PointU(Unit.Inch(0.7D), Unit.Inch(0.6D));<br>this.crosstab1.Name = "crosstab1";<br>this.crosstab1.Size = new SizeU(Unit.Inch(2.3D), Unit.Inch(1.7D));

The following sets the style of the crosstab (you can view in the crosstab wizard the predefined tabs):
this.crosstab1.StyleName = "Normal.TableNormal";

You can also create nested table groups. The basic idea is that you create two table groups and then add one of them as child group to the second one. Then you add the second table group as row or column group to the crosstab. Check this code to see how this is done:
// Create the first table group
tableGroup1.Groupings.AddRange(new Grouping[] {new Grouping("=Fields.AddressLine2")});
tableGroup1.Name = "AddressLine21";
tableGroup1.ReportItem = this.textBox1;
tableGroup1.Sortings.AddRange(new Sorting[] {new Sorting("=Fields.AddressLine2", SortDirection.Asc)});
 
// Create the second table group and add the first one as child
tableGroup2.ChildGroups.Add(tableGroup1);
tableGroup2.Groupings.AddRange(new Grouping[] {new Grouping("=Fields.AddressLine1")});
tableGroup2.Name = "AddressLine11";
tableGroup2.ReportItem = this.textBox2;
tableGroup2.Sortings.AddRange(new Sorting[] {new Sorting("=Fields.AddressLine1", SortDirection.Asc)});
 
// Add the second (parent) group to the column or row groups of the crosstab
this.crosstab1.ColumnGroups.Add(tableGroup2);

Regards,
IvanY
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Tags
General Discussions
Asked by
Grégory
Top achievements
Rank 1
Answers by
IvanY
Telerik team
Share this question
or