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

GridView.CalcRowHeight Event

Enables you to provide custom heights for individual rows.

Namespace: DevExpress.XtraGrid.Views.Grid

Assembly: DevExpress.XtraGrid.v18.2.dll

Declaration

[DXCategory("Appearance")]
public event RowHeightEventHandler CalcRowHeight

Event Data

The CalcRowHeight event's data class is RowHeightEventArgs. The following properties provide information specific to this event:

Property Description
RowHandle Gets the handle of the row whose height is to be specified.
RowHeight Gets or sets the row’s height.

Remarks

By default, the height of all rows is fixed and is specified by the GridView.RowHeight and GridView.GroupRowHeight properties. These properties set the height of data rows and group rows respectively.

The GridOptionsView.RowAutoHeight setting can be used to enable the row auto height feature, which automatically applies the “best” height to rows to display row contents in their entirety. In this mode, different rows may have different heights.

To specify the height of individual rows based on custom logic, handle the CalcRowHeight event. The event is raised repeatedly for each row. The currently processed row is specified by the event’s RowHeightEventArgs.RowHandle parameter. To change the row’s height, assign the required value to the RowHeightEventArgs.RowHeight parameter.

Note

If you subscribe to this event at runtime, your event handler may not be called immediately. The event handler will be raised after the grid’s layout is changed. You can manually invoke the layout change action, and thus your CalcRowHeight event handler, by calling the BaseView.LayoutChanged method after the event subscription.

Example

The following code demonstrates a GridView.CalcRowHeight event handler.

This event is used to specify heights of individual rows. It is assumed that a View (gridView1) displays data from the DataView data source, which contains the RowHeight column. This column specifies the height to set for a specific row.

using DevExpress.XtraGrid.Views.Grid;

private void gridView1_CalcRowHeight(object sender, RowHeightEventArgs e) {
    GridView view = sender as GridView;
    if (view == null) return;
    if(e.RowHandle >= 0)
        e.RowHeight = (int)view.GetDataRow(e.RowHandle)["RowHeight"];
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the CalcRowHeight event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also