Category / Section
How to resize the columns when some rows are hidden in WinForms GridControl?
2 mins read
Resize the columns
In order to
resize the columns based on its content when some of the rows are hidden, the ResizeToFitOptimized method
can be used.
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);
}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

After
resizing

Samples: