Articles in this section
Category / Section

How to resize the columns when some rows are hidden in WinForms GridControl?

1 min read

Resize the columns

In order to resize the columns based on its content when some of the rows are hidden, ResizeToFitOptimized method can be used.

C#

private void Button1_Click(object sender, EventArgs e)
{
   //Hiding the rows.
   this.gridControl1.HideRows[5] = true;
   this.gridControl1.HideRows[8] = true;
   //Resize the columns.                  GridControl1.ColWidths.ResizeToFitOptimized(GridRangeInfo.Cols(1,GridControl1.ColCount),GridResizeToFitOptions.NoShrinkSize);
}

 

VB

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
   'Hiding the rows
   Me.gridcontrol1.HideRows[5] = true;
   Me.gridcontrol1.HideRows[8] = true; 
   ‘Resize the columns.
GridControl1.ColWidths.ResizeToFitOptimized(GridRangeInfo.Cols(1,GridControl1.ColCount),GridResizeToFitOptions.NoShrinkSize);
End Sub

 

Screenshot

Before resizing

Before resizing the column in grid

 

After resizing

After resizing the column in grid

Samples:

C#: Resizing_Columns_CS

VB: Resizing_Columns_VB

 

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