Back to Devexpress

XRControl.CanGrow Property

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xrcontrol-d9410c04.md

latest5.4 KB
Original Source

XRControl.CanGrow Property

Gets or sets a value indicating whether the control’s height can grow in order to display the content in its entirety.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
[Browsable(false)]
[DefaultValue(true)]
[SRCategory(ReportStringId.CatBehavior)]
public virtual bool CanGrow { get; set; }
vb
<SRCategory(ReportStringId.CatBehavior)>
<Browsable(False)>
<DefaultValue(True)>
Public Overridable Property CanGrow As Boolean

Property Value

TypeDefaultDescription
Booleantrue

true , if the control’s height can grow in order to display the entire content; otherwise, false.

|

Remarks

When the CanGrow property is enabled, the control’s height can be automatically increased to display the entire content. Any other report elements that may reside below the current control will be moved down to prevent them from overlapping.

If a control already overlaps the growing control by even one pixel, it will not be pushed down by the growing control.

The CanGrow and XRControl.CanShrink property values are ignored if the XRControl.AnchorVertical property is set to VerticalAnchorStyles.Bottom or VerticalAnchorStyles.Both.

Not all descendants of the XRControl class use the CanGrow property. For example, the Band class descendants ignore the CanGrow property.

Example

The code sample below illustrates how to create an XRLabel object and bind it to data. You should bind your report to the Northwind database’s Products table for this example to work properly.

To learn about the events available for a report and its controls, see Report Events.

csharp
using System;
using System.Drawing;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...

public partial class XtraReport1 : XtraReport {

    public XRLabel CreateXRLabel() {
        // Create a new label object.
        XRLabel label = new XRLabel();

        // Bind the label to the UnitPrice data field. 
        // Change the label's foreground color depending on the UnitPrice data field value.
        label.ExpressionBindings.AddRange(new ExpressionBinding[] {
        new ExpressionBinding("BeforePrint", "Text", "[UnitPrice]"),
        new ExpressionBinding("BeforePrint", "ForeColor", "Iif([UnitPrice]>20, \'Red\', \'Green\')")});

        // Apply a currency format to the label's text.
        label.TextFormatString = "{0:c2}";

        // Automatically adjust the label's width to its content.
        label.AutoWidth = true;

        // Align the label's text to the bottom right corner.
        label.TextAlignment = TextAlignment.BottomRight;

        return label;
    }

    public XtraReport1() {
        // ...
        // Add the label to the report's Detail band.
        XRLabel label = CreateXRLabel();
        this.Detail.Controls.Add(label);
    }
}
vb
Imports System.Drawing
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraPrinting
' ...

Public Partial Class XtraReport1
    Inherits XtraReport

    Public Function CreateXRLabel() As XRLabel
        ' Create a new label object.
        Dim label As New XRLabel()

        ' Bind the label to the UnitPrice data field. 
        ' Change the label's foreground color depending on the UnitPrice data field value.
        label.ExpressionBindings.AddRange(New ExpressionBinding() {
        New ExpressionBinding("BeforePrint", "Text", "[UnitPrice]"),
        New ExpressionBinding("BeforePrint", "ForeColor", "Iif([UnitPrice]>20, 'Red', 'Green')")})

        ' Apply a currency format to the label's text.
        label.TextFormatString = "{0:c2}"

        ' Automatically adjust the label's width to its content.
        label.AutoWidth = True

        ' Align the label's text to the bottom right corner.
        label.TextAlignment = TextAlignment.BottomRight

        Return label
    End Function

    Public Sub New()
        ' ...
        ' Add the label to the report's Detail band.
        Dim label As XRLabel = CreateXRLabel()
        Me.Detail.Controls.Add(label)
    End Sub
End Class

See Also

CanShrink

XRControl Class

XRControl Members

DevExpress.XtraReports.UI Namespace