Within the Report.ItemDataBinding event I'm adjusting the Textbox positions within the PageHeader inorder to collapse the height.
ItemDataBindingEvent
- Loop Items
- If (Empty) Visibility = False
- Loop each items that crosses vertical plane below this item
- BelowItem.Top = BelowItem.Top.Subtract(hiddenItemHeightUnit);
lowest = pageSection.Items.OrderByDescending(x => x.Bottom.Value).FirstOrDefault();
if (lowest.Bottom.Value + threashold > pageHeader.Height.Value)
pageHeader.Height = new Telerik.Reporting.Drawing.Unit.Inch(lowest.Bottom.Value + paddingBottom);
This works great except if I have a textbox that is flush to the right border (textAlign.Right). Within the ReportHeaderSection ItemDataBound event I can verify that the LEFT position is correctly set within the Processing Textbox and the ItemDefinition Textbox, but when rendered its the same as float left.
If I have a textbox in the center and not even the same horzontal row then this does not happend
This is my page header
-----------------------------------------------
[ Sup Title ]
[ Title ]
[ Value1 ] [Sub Title] ]
[ Value2 ] ]
[ Value3 ] [ Value4]
-----------------------------------------------
If I set any of the textbox visiblity to false, then all of the textboxes render as float left (SubTitle and Value4)
If I set their height to Zero then re-positioning is possible.
ItemDataBindingEvent
- Loop Items
- If (Empty) Visibility = False
- Loop each items that crosses vertical plane below this item
- BelowItem.Top = BelowItem.Top.Subtract(hiddenItemHeightUnit);
lowest = pageSection.Items.OrderByDescending(x => x.Bottom.Value).FirstOrDefault();
if (lowest.Bottom.Value + threashold > pageHeader.Height.Value)
pageHeader.Height = new Telerik.Reporting.Drawing.Unit.Inch(lowest.Bottom.Value + paddingBottom);
This works great except if I have a textbox that is flush to the right border (textAlign.Right). Within the ReportHeaderSection ItemDataBound event I can verify that the LEFT position is correctly set within the Processing Textbox and the ItemDefinition Textbox, but when rendered its the same as float left.
If I have a textbox in the center and not even the same horzontal row then this does not happend
This is my page header
-----------------------------------------------
[ Sup Title ]
[ Title ]
[ Value1 ] [Sub Title] ]
[ Value2 ] ]
[ Value3 ] [ Value4]
-----------------------------------------------
If I set any of the textbox visiblity to false, then all of the textboxes render as float left (SubTitle and Value4)
If I set their height to Zero then re-positioning is possible.
/// <
summary
>
/// Can only shrink content within the Report.ItemDataBinding Event
/// </
summary
>
/// <
param
name
=
"pageHeader"
></
param
>
/// <
param
name
=
"debug"
></
param
>
public static void ShrinkToContent(this Telerik.Reporting.PageHeaderSection pageHeader, double paddingBottom=0.02D, bool debug=false)
{
var items = pageHeader.Items.OfType<
Telerik.Reporting.TextBox
>().Where(x => x.Visible).OrderBy(x => x.Top.Value).ToList();
double threashold = 0.02;
foreach (Telerik.Reporting.TextBox tx in items)
{
tx.CanGrow = false;
if (string.IsNullOrEmpty(tx.Value))
{
// shuffle items beneth this textbox
foreach (Telerik.Reporting.TextBox item in items.Where(x => x.Visible && x.Top.Value > tx.Top.Value && tx.Left.Value <
x.Right.Value
&& x.Left.Value < tx.Right.Value))
{
//
item.Location
=
new
Telerik.Reporting.Drawing.PointU(item.Left, item.Top.Subtract(tx.Height));
item.Top
= item.Top.Subtract(tx.Height);
if (debug)
{
// blue means shiffted
item.Style.BackgroundColor
=
System
.Drawing.Color.Blue;
}
}
tx.Height
=
Telerik
.Reporting.Drawing.Unit.Zero;
tx.CanShrink
=
true
;
//
tx.Style.BackgroundColor
=
System
.Drawing.Color.Black;
}
}
var
stacked
=
items
.OrderByDescending(x => (x.Height.Value <= threashold) ? 0 : x.Bottom.Value).ToList();
var lowest = stacked.FirstOrDefault();
// TODO
// If we have a bottom alignment ensure that its bumped up and still on the bottom
// Colapse between lowest and next above in vertical stack
double oldHeight = pageHeader.Height.Value;
double newHeight = lowest.Bottom.Value;
if (newHeight < (oldHeight + threashold))
{
if (debug)
{
pageHeader.Style.BackgroundColor = System.Drawing.Color.Yellow;
}
pageHeader.Height = Telerik.Reporting.Drawing.Unit.Inch(newHeight + paddingBottom);
}
}