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
After resizing
Samples: