xtrareports-120028-feature-guide-to-devexpress-reports-use-report-controls-use-tables-hide-table-cells.md
This help topic describes how you can hide a table cell conditionally, based on the report parameter value.
Start with a Table report bound to the Products table of the Sample Northwind Database.
Right-click the Parameters section in the Field List and select Add Parameter.
In the invoked Add New Parameter dialog, specify the name ( showCatID ) and description ( Show Category ID ), and set the type to Boolean:
You can use the following methods to hide a table cell.
Specify an expression for the cell’s Visible property to define a logical condition to display or hide that cell.
In this example, the showCatID report parameter determines whether the cell bound to the CategoryID field is displayed. The expression bound to the Visible property is as follows:
?showCatID
You should also specify the same expression for the Visibility property of the Category ID cell in the header table.
Handle the report’s BeforePrint event to set the table cell’s Visible property to False when a certain condition is met.
private void XtraReport1_BeforePrint(object sender, System.ComponentModel.EventArgs e) {
if (Convert.ToBoolean(showCatID.Value)) {
xrTableCell2.Visible = true;
xrTableCell6.Visible = true;
}
else {
xrTableCell2.Visible = false;
xrTableCell6.Visible = false;
}
}
Private Sub XtraReport1_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.EventArgs)
If Convert.ToBoolean(showCatID.Value) Then
xrTableCell2.Visible = True
xrTableCell6.Visible = True
Else
xrTableCell2.Visible = False
xrTableCell6.Visible = False
End If
End Sub
Set the event argument’s Cancel property to True in the cell’s BeforePrint event handler:
private void xrTableCell2_BeforePrint(object sender, System.ComponentModel.EventArgs e) {
if (!Convert.ToBoolean(showCatID.Value))
e.Cancel = true;
}
private void xrTableCell6_BeforePrint(object sender, System.ComponentModel.EventArgs e) {
if (!Convert.ToBoolean(showCatID.Value))
e.Cancel = true;
}
Private Sub xrTableCell2_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.EventArgs)
If Not Convert.ToBoolean(showCatID.Value) Then e.Cancel = True
End Sub
Private Sub xrTableCell6_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.EventArgs)
If Not Convert.ToBoolean(showCatID.Value) Then e.Cancel = True
End Sub
Use the ProcessHiddenCellMode property to define how to distribute the remaining space between visible table cells.
The image below shows the original table:
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.
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.
ResizeCellsEqually
All visible cells are resized to equally divide the space that a hidden cell previously occupied before it was hidden.
ResizeCellsProportionally
All visible cells are resized to proportionally divide the space that a hidden cell previously occupied based on their weights relative to the entire table width.
DecreaseTableWidth
The table width is decreased, and visible cells are shifted to a hidden cell’s location without changing their size.
LeaveEmptySpace
The default mode. An empty space remains at a hidden cell’s location and other cells are not affected.
The resulting report appears as follows:
Tutorials that explain how to use different report elements in EUD Report Designers for WinForms and Web are included in the End-User Documentation online help section: