I have ContextMenuStrip that on right click shows something to choose from. It's working perfect when the cell is not in edit mode but when it's in edit mode when I click the right mouse button it shows windows menu (copy,paste,delete, select all...). So in the datagridview I hadnled the CellEndEdit and there wrote this code:
if (MouseButton == System.Windows.Forms.MouseButtons.Right)
{
MouseEventArgs e3 = new MouseEventArgs(System.Windows.Forms.MouseButtons.Right, 1, Location.X,
Location.Y, 1);
DataGridViewCellMouseEventArgs e2 = new DataGridViewCellMouseEventArgs(e.ColumnIndex,
e.RowIndex, Location.X, Location.Y, e3);
DataGridValues_CellMouseClick(sender, e2);
}
Where the MouseButton
is MouseButtons
. It enteres and do everything but I got the 2 menus(mine and the windows). So I need to disable the windows right click menu. Is there a way to do this? I think the code in DataGridValues_CellMouseClick(sender, e2);
doesnt matter because it's working.
Try like this
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
e.Control.ContextMenuStrip = myContextMenuStrip;
}