GridView.CalcRowHeight Event
Enables you to provide custom heights for individual rows.
Namespace: DevExpress.XtraGrid.Views.Grid
Assembly: DevExpress.XtraGrid.v24.1.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
Declaration
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 will be raised next time the Grid layout changes. You can call BaseView.LayoutChanged method to manually trigger the event.
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"];
}