We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to resize row height based on the font of Grid cell content in WinForms GridControl?

Platform: WinForms |
Control: GridControl
Tags: row, sizing

Resize the row height

In order to resize the row height based on the cell content height, the ResizingRows event can be used. The resizing value is calculated from the content height using MeasuringString() method.

The rows individually can be resized using the AllowResizingIndividualRows() method of GridHelperclasses.


GridEngineFactory.Factory = new Syncfusion.GridHelperClasses.AllowResizingIndividualRows();
gridControl1.ResizingRows += gridControl1_ResizingRows;
Size stringSize;
void gridControl1_ResizingRows(object sender, GridResizingRowsEventArgs e)
     if (e.Reason == GridResizeCellsReason.DoubleClick)
         Graphics grapics = CreateGraphics();
         long maxHeight = 0;
         GridStyleInfo style = this.gridControl1.GetViewStyleInfo(e.Rows.Bottom, 1);
         stringSize = grapics.MeasureString(style.Text, style.GdipFont).ToSize();
         if (maxHeight < stringSize.Height)
             maxHeight = (long)stringSize.Height;
         this.gridControl1.Model.RowHeights[e.Rows.Bottom] = (int)maxHeight;
         e.Cancel = true;



GridEngineFactory.Factory = New Syncfusion.GridHelperClasses.AllowResizingIndividualRows()
AddHandler gridControl1.ResizingRows, AddressOf gridControl1_ResizingRows
Dim stringSize As Size
void gridControl1_ResizingRows(Object sender, GridResizingRowsEventArgs e)
  If e.Reason = GridResizeCellsReason.DoubleClick Then
   Dim grapics As Graphics = CreateGraphics()
   Dim maxHeight As Long = 0
   Dim style As GridStyleInfo = Me.gridControl1.GetViewStyleInfo(e.Rows.Bottom, 1)
   stringSize = grapics.MeasureString(style.Text, style.GdipFont).ToSize()
   If maxHeight < stringSize.Height Then
    maxHeight = CLng(Fix(stringSize.Height))
   End If
   Me.gridControl1.Model.RowHeights(e.Rows.Bottom) = CInt(Fix(maxHeight))
   e.Cancel = True
  End If



Resize the row height based on the font


C#: RowHeight_CS

VB: RowHeight_VB


2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile