Reputation: 53
I have a DataGridView with a dgv1.CellClick.
The context menu shows up with the cell is clicked with the left mouse button. When this happens it also sets the position to the current cell BUT the contextmenustrip also shows up when I click on the RIGHT mouse button. I want to disable or hide the context menu when the right mouse button is clicked.
I have tried:
private void dgv1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
cms1.Hide();
}
and this did not work.
Does anyone have any advice?
Upvotes: 0
Views: 7004
Reputation: 53
private MouseButtons e_Button = new MouseButtons();
private void dgv1_MouseDown(object sender, MouseEventArgs e)
{
e_Button = e.Button;
}
private void cms1_Opening(object sender, CancelEventArgs e)
{
if (e_Button == System.Windows.Forms.MouseButtons.Right)
e.Cancel = true;
}
Upvotes: 3
Reputation: 2612
private void dataGridViewExample_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
e.Control.ContextMenu = new ContextMenu();
}
Upvotes: 0
Reputation: 689
Try this
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
e.Control.ContextMenu = new ContextMenu();
}
Upvotes: 0
Reputation: 11063
Maybe with this:
private void dgv1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
if ((e.Button != Windows.Forms.MouseButtons.Right)) {
cms1.Show(datagridview, e.Location);
}
}
}
Upvotes: 0