Back to Devexpress

How to: Dynamically Control the Height of Individual Rows

windowsforms-3054-controls-and-libraries-data-grid-examples-data-presentation-how-to-dynamically-control-the-height-of-individual-rows.md

latest1.2 KB
Original Source

How to: Dynamically Control the Height of Individual Rows

  • Nov 13, 2018

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.

csharp
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"];
}
vb
Imports DevExpress.XtraGrid.Views.Grid

Private Sub GridView1_CalcRowHeight(ByVal sender As Object, _
ByVal e As RowHeightEventArgs) Handles GridView1.CalcRowHeight
   Dim view As GridView = sender
   If view Is Nothing Then
       Return
   End If
   If e.RowHandle >= 0 Then
       e.RowHeight = view.GetDataRow(e.RowHandle)("RowHeight")
   End If
End Sub