Category / Section
How to Hide Context Menu when You Click Header in WinForms GridControl?
Hide the context menu
By default, ContextMenu opens when clicking on header cells. However, you can hide the context menu when clicking the header cells in WinForms GridControl by using the contextMenuStripEx1_Opening event.
//Event triggered from Form_load
this.contextMenuStripEx1.Opening += contextMenuStripEx1_Opening;
void contextMenuStripEx1_Opening(object sender, CancelEventArgs e)
{
int R_index = this.gridControl1.CurrentCell.RowIndex;
int C_index = this.gridControl1.CurrentCell.ColIndex;
if (R_index == 0 || C_index == 0)
//ContextMenuStrip removed for headers
e.Cancel = true;
else
e.Cancel = false;
}'Event triggered from Form_load
AddHandler Me.contextMenuStripEx1.Opening, AddressOf contextMenuStripEx1_Opening
Private Sub contextMenuStripEx1_Opening(ByVal sender As Object, ByVal e As CancelEventArgs)
Dim R_index As Integer = Me.gridControl1.CurrentCell.RowIndex
Dim C_index As Integer = Me.gridControl1.CurrentCell.ColIndex
If R_index = 0 OrElse C_index = 0 Then
'ContextMenuStrip removed for headers
e.Cancel = True
Else
e.Cancel = False
End If
End Sub