Articles in this section

How to disable the contextmenu for a specific row in WinForms GridGroupingControl?

Context menu


To display a context menu based on the cell value in WinForms GridGroupingControl, use the TableControl.MouseDown event. In this event, a specific cell value can be retrieved from the current record using the current cell style and setting the ContextMenu based on the cell value.


//Event Subscription
 this.gridGroupingControl1.TableControl.MouseDown += TableControl_MouseDown;
 
//Event Customization
 private void TableControl_MouseDown(object sender, MouseEventArgs e)
 {
    if (e.Button == MouseButtons.Right)
    {
        int rowIndex, colIndex;
        this.gridGroupingControl1.TableControl.PointToRowCol(e.Location, out rowIndex, out colIndex);
        //To get the current cell style.
        GridTableCellStyleInfo style = this.gridGroupingControl1.TableControl.GetTableViewStyleInfo(rowIndex, colIndex);
        //To get the record.
        Record record = style.TableCellIdentity.DisplayElement.GetRecord();
        if(record != null)
        {
            bool value;
            string boolValue = record.GetValue("Boolean").ToString();
            if (bool.TryParse(boolValue, out value) && value)
                this.gridGroupingControl1.ContextMenu = null;
           else if (this.gridGroupingControl1.ContextMenu == null)
                this.gridGroupingControl1.ContextMenu = menu;
        }
        else
        {
            //To avoid the contextmenu for header row.
            this.gridGroupingControl1.ContextMenu = null;
        }
    }
}
'Event Subscription
AddHandler Me.gridGroupingControl1.TableControl.MouseDown, AddressOf TableControl_MouseDown
 
'Event Customization
Private Sub TableControl_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
   If e.Button = MouseButtons.Right Then
       Dim rowIndex, colIndex As Integer
       Me.gridGroupingControl1.TableControl.PointToRowCol(e.Location, rowIndex, colIndex)
       'To get the current cell style.
       Dim style As GridTableCellStyleInfo = Me.gridGroupingControl1.TableControl.GetTableViewStyleInfo(rowIndex, colIndex)
       'To get the record.
       Dim record As Record = style.TableCellIdentity.DisplayElement.GetRecord()
       If record IsNot Nothing Then
          Dim value As Boolean
          Dim boolValue As String = record.GetValue("Boolean").ToString()
          If Boolean.TryParse(boolValue, value) AndAlso value Then
  Me.gridGroupingControl1.ContextMenu = Nothing
          ElseIf Me.gridGroupingControl1.ContextMenu Is Nothing Then
   Me.gridGroupingControl1.ContextMenu = menu_Renamed
          End If
          Else
  'To avoid the contextmenu for header row.
  Me.gridGroupingControl1.ContextMenu = Nothing
          End If
       End If
End Sub

The below screenshot illustrates the disabling of ContextMenu for a specific row in GridGroupingControl.

Show the context menu


Samples:

C#: Disable contextmenu on Booleanvalue_CS

VB: Disable contextmenu on Booleanvalue_VB

 

Conclusion


I hope you enjoyed learning about how to disable the context menu for a specific row in the GridGroupingControl.


You can refer to our WinForms GridGroupingControl’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGroupingControl documentation to understand how to present and manipulate data.

 

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms GridGroupingControl and other WinForms components.

 

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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