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

Set Crosstab locaton in page programmatcally

2 Answers 34 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Fatima
Top achievements
Rank 1
Fatima asked on 29 Oct 2012, 06:29 AM
Hi everyone

I need to set my crosstab position programmatically, because it has different number of columns based on user options. So I want to show it in the center (horizontally) of page every time.

I used of location (x , y) based on dimension of page and number of crosstab columns for it in my c# code, but it is not effective at all.

Thanks for your guides

2 Answers, 1 is accepted

Sort by
0
IvanY
Telerik team
answered on 31 Oct 2012, 04:38 PM
Hi Fatima,

It depends how you are creating your Crosstab and how you are adding columns. For example you can use the ItemDataBound event handler like this:
private void crosstab1_ItemDataBound(object sender, EventArgs e)
{
    var table = (Telerik.Reporting.Processing.Table)sender;
    var x = this.PageSettings.Landscape ?
            (this.PageSettings.PaperSize.Height - (this.PageSettings.Margins.Left + this.PageSettings.Margins.Right + table.Width)) / 2 :
            (this.PageSettings.PaperSize.Width - (this.PageSettings.Margins.Left + this.PageSettings.Margins.Right + table.Width)) / 2;
    var y = table.Location.Y;
 
    table.Location = new Telerik.Reporting.Drawing.PointU(x, y);
}

If that does not solve your issue please elaborate.

Greetings,
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!

0
Ken Lewis
Top achievements
Rank 1
answered on 20 Nov 2012, 08:18 PM
That is a very helpful solution and helped me solve a similar scenario, but it was only centering based on the base table. It did not include the dynamically added Crosstab columns. I added the second and third code lines below (see const and var) to achieve true centering. (Note: My base table has three columns, which is why I subtract that number below.)

private void vitalSystemsCrosstab_ItemDataBound(object sender, EventArgs e)
{
    var table = (Telerik.Reporting.Processing.Table)sender;          
     
    const double columnWidth = 0.3;           
    var extraColumnsWidth = new Unit((table.Columns.Count - 3) * columnWidth, UnitType.Inch);
 
    var x = this.PageSettings.Landscape ?
            (this.PageSettings.PaperSize.Height - (this.PageSettings.Margins.Left + this.PageSettings.Margins.Right + table.Width + extraColumnsWidth)) / 2 :
            (this.PageSettings.PaperSize.Width - (this.PageSettings.Margins.Left + this.PageSettings.Margins.Right + table.Width + extraColumnsWidth)) / 2;
    var y = table.Location.Y;
 
    table.Location = new Telerik.Reporting.Drawing.PointU(x, y);
}

I hope others find it helpful.

Ken
Tags
General Discussions
Asked by
Fatima
Top achievements
Rank 1
Answers by
IvanY
Telerik team
Ken Lewis
Top achievements
Rank 1
Share this question
or