views:

1015

answers:

1

Does anyone know how I can disable the System Context Menu when a user right clicks in a DataGridViewTextBoxCell? I have tried to override the WndProc at the DataGridView level (as there is no WndProc to override on the Cell level), but nothing seems to work. Any help would be greatly appreciated.

The following is what I use to achieve this in a regular TextBox, however, I need to work the same way for a DataGridViewCell?

public  class NoContextTextBox : TextBox {
    private static readonly int WM_CONTEXTMENU = 123;
    protected override void WndProc(ref Message m) {
        if (m.Msg != WM_CONTEXTMENU) {
            base.WndProc(ref m);
        }
    }
}
+1  A: 

This worked for me:

   private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        e.Control.ContextMenu = new ContextMenu();
    }

Just set the ContextMenu property to new (empty) ContextMenu in the EditingControlShowing event of the DataGridView.

Mr. Brownstone
You are my hero.
sbeskur