Category / Section
How to unhide the column after dragging it to hide in WinForms GridControl?
2 mins read
Resizing hidden column
The default behavior to unhide a column is to double click the column’s border. When you just want to drag and resize the hidden columns, you can do it by handling the ResizingCols event.
In the following code example resizing hidden columns in gridcontrol is done by using the gridControl1_ResizingColumns event.
C#
private void gridControl1_ResizingColumns(object sender, Syncfusion.Windows.Forms.Grid.GridResizingColumnsEventArgs e) { //To unhide the column after dragging it to hide if(e.Reason == GridResizeCellsReason.MouseUp) { int left = e.Columns.Left; GridControlBase grid = sender as GridControlBase ; if(left == e.Columns.Right && left < grid.Model.ColCount&& grid.Model.Cols.Hidden[left + 1]) { e.Cancel = true; grid.Model.Cols.Hidden[left + 1] = false; grid.Model.ColWidths[left + 1] = e.Width - grid.Model.ColWidths[left]; } } }
VB
Private Sub gridControl1_ResizingColumns(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridResizingColumnsEventArgs) Handles gridControl1.ResizingColumns 'To unhide the column after dragging it to hide If e.Reason = GridResizeCellsReason.MouseUp Then Dim left As Integer = e.Columns.Left Dim grid As GridControlBase = TryCast(sender, GridControlBase) If left = e.Columns.Right AndAlso left < grid.Model.ColCount AndAlso grid.Model.Cols.Hidden(left + 1) Then e.Cancel = True grid.Model.Cols.Hidden(left + 1) = False grid.Model.ColWidths(left + 1) = e.Width - grid.Model.ColWidths(left) End If End If End Sub
Note:
When you want Excel-like behavior to show the vertical split when the columns are hidden, you can achieve this by implementing your own mouse controller.