Skip to main content
A newer version of this page is available. .

Hide Table Cells

  • 3 minutes to read

You can hide a specific table cell conditionally, for instance, based on a report parameter value.

Right-click the Parameters section in the Field List and select Add Parameter.

table-hiding-cell-create-parameter

In the invoked Add New Parameter dialog, specify the parameter’s name and description for Print Preview, and set the type to Boolean.

table-hiding-cell-parameter-settings

You can use the following approaches to hide a table cell:

  • Specify an expression for the cell’s XRControl.Visible property to define a logical condition for displaying or hiding this cell.

    The image below demonstrates how to provide the visibility expression for the cell bound to the CategoryID field. For a report to display correctly, you should specify the same expression for the cell displaying the field caption in the Page Header.

    table-hide-cell-using-visible-expression

  • Set the table cell’s XRControl.Visible property to false at runtime when a specific condition is met (for example, by handling the report’s XRControl.BeforePrint event).

    private void XtraReport1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
        if (Convert.ToBoolean(showCatID.Value)) {
            xrTableCell2.Visible = true;
            xrTableCell6.Visible = true;
        }
        else {
            xrTableCell2.Visible = false;
            xrTableCell6.Visible = false;
        }
    }
    
  • In the cell’s XRControl.BeforePrint event handler, set the event argument’s Cancel property to true.

    private void xrTableCell2_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
        if (!Convert.ToBoolean(showCatID.Value))
            e.Cancel = true;
    }
    
    private void xrTableCell6_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
        if (!Convert.ToBoolean(showCatID.Value))
            e.Cancel = true;
    }
    

Use the XRTable.ProcessHiddenCellMode property to define how to distribute the remaining space between the table’s visible cells.

table-process-hidden-cell-mode-property

The image below illustrates how an original table looks like:

table-hidden-cell-mode-initial-layout

The following processing modes are available:

  • StretchPreviousCell

    A cell located to the left of the hidden cell is stretched to occupy the available space. If the hidden cell is the first in the row, the next cell is stretched.

    table-hidden-cell-mode-stretch-previous-cell

  • StretchNextCell

    A cell located to the right of the hidden cell is stretched to occupy the available space. If the hidden cell is the last in the row, the previous cell is stretched.

    table-hidden-cell-mode-stretch-next-cell

  • ResizeCellsEqually

    All visible cells are resized to equally divide the space that a hidden cell reserved.

    table-hidden-cell-mode-resize-cells-equally

  • ResizeCellsProportionally

    All visible cells are resized to proportionally divide the space that a hidden cell reserved based on their weights in the whole table width.

    table-hidden-cell-mode-resize-cells-proportionally

  • DecreaseTableWidth

    The table width is decreased, and visible cells are shifted to a hidden cell’s location without changing their size.

    table-hidden-cell-mode-decrease-table-width

  • LeaveEmptySpace

    The default mode. An empty space remains at a hidden cell’s location and other cells are not affected.

    table-hidden-cell-mode-leave-empty-space