Articles in this section
Category / Section

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

2 mins read

Resize the row height

In order to resize the row height based on the cell content height in WinForms Grid Control, 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


I hope you enjoyed learning about how to resize row height based on the font of Grid cell content in WinForms GridControl.

You can refer to our  WinForms Grid Control’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms Grid Control documentation to understand how to present and manipulate data. 

For current customers, you can check out our WinForms from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms Grid Control and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment