We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to restrict the removing of grouped columns from GroupDropArea when AllowRemove is enabled in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl


To restrict the removing of grouped columns from GroupDropArea when AllowRemove is enabled for grouped columns, the CellClick event of GridGroupDropArea can be used.

In CellClick event, button bounds for remove option can be calculated and the removing of grouped columns can be restricted by disabling the clicking event using e.Cancel property when clicking bounds is on the remove button bounds.


//Triggering the event.
this.gridGroupingControl1.GridGroupDropArea.CellClick += GridGroupDropArea_CellClick;
//Event Customization.
private void GridGroupDropArea_CellClick(object sender, Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs e)
    GridGroupDropArea groupDropArea = sender as GridGroupDropArea;
    GridStyleInfo style = groupDropArea.Model[e.RowIndex, e.ColIndex];
    string cellValue = style.CellValue.ToString();
    Rectangle buttonBounds = ButtonArea(groupDropArea,e.RowIndex, e.ColIndex);
    if ((cellValue == "Description" || cellValue == "CategoryID") &&
        buttonBounds.Contains(e.MouseEventArgs.X, e.MouseEventArgs.Y))
        e.Cancel = true;
//Calculate the ButtonBounds for Remove button.
private Rectangle GetRemoveButtonBounds(GridGroupDropArea groupdropArea,int rowIndex,int colIndex)
    Rectangle cellBounds = groupdropArea.GetCellRenderer(rowIndex, colIndex).GetCellBoundsCore(rowIndex, colIndex);
    Rectangle innerBounds;
    Rectangle buttonsBounds;
    int buttonWidth = 8;
    innerBounds = cellBounds;
    Rectangle buttonArea = Rectangle.FromLTRB((((innerBounds.Right + 2 - (buttonWidth * 2)))), (innerBounds.Top - 1), (innerBounds.Right), innerBounds.Bottom);
    if (groupdropArea.GroupingControl.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
        buttonArea = Rectangle.FromLTRB(innerBounds.Left, (innerBounds.Top - 1), (((innerBounds.Left + (buttonWidth * 2)))), innerBounds.Bottom);
    buttonsBounds = GridUtil.CenterInRect(buttonArea, new Size(buttonWidth, 20));
    return buttonsBounds;



'Triggering the event.
AddHandler Me.gridGroupingControl1.GridGroupDropArea.CellClick, AddressOf GridGroupDropArea_CellClick
'Event Customization.
Private Sub GridGroupDropArea_CellClick(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs)
    Dim groupDropArea As GridGroupDropArea = TryCast(sender, GridGroupDropArea)
    Dim style As GridStyleInfo = groupDropArea.Model(e.RowIndex, e.ColIndex)
    Dim cellValue As String = style.CellValue.ToString()
    Dim buttonBounds As Rectangle = GetRemoveButtonBounds (groupDropArea,e.RowIndex, e.ColIndex)
    If (cellValue = "Description" OrElse cellValue = "CategoryID") AndAlso buttonBounds.Contains(e.MouseEventArgs.X, e.MouseEventArgs.Y) Then
        e.Cancel = True
    End If
End Sub
'Calculate the ButtonBounds for Remove button.
Private Function GetRemoveButtonBounds (ByVal groupdropArea As GridGroupDropArea, ByVal rowIndex As Integer, ByVal colIndex As Integer) As Rectangle
    Dim cellBounds As Rectangle = groupdropArea.GetCellRenderer(rowIndex, colIndex).GetCellBoundsCore(rowIndex, colIndex)
    Dim innerBounds As Rectangle
    Dim buttonsBounds As Rectangle
    Dim buttonWidth As Integer = 8
    innerBounds = cellBounds
    Dim buttonArea_Renamed As Rectangle = Rectangle.FromLTRB((((innerBounds.Right + 2 - (buttonWidth * 2)))), (innerBounds.Top - 1), (innerBounds.Right), innerBounds.Bottom)
    If groupdropArea.GroupingControl.RightToLeft = System.Windows.Forms.RightToLeft.Yes Then
        buttonArea_Renamed = Rectangle.FromLTRB(innerBounds.Left, (innerBounds.Top - 1), (((innerBounds.Left + (buttonWidth * 2)))), innerBounds.Bottom)
    End If
    buttonsBounds = GridUtil.CenterInRect(buttonArea_Renamed, New Size(buttonWidth, 20))
    Return buttonsBounds
End Function



C#: Grouped Columns CS

VB: Grouped Columns VB

Reference link: https://help.syncfusion.com/windowsforms/classic/gridgroupingcontrol/grouping

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile