Reputation: 1
Why in every right click, the contextmenustrip pop up,how to enable it in a specify position by controlling the right click event??
Upvotes: 0
Views: 33
Reputation: 156
Try to remove the default contextmenustrip and create a new one. With HitTest on a control you can check if the clicked position is on a element
private void MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
if (dataGrid.HitTest(e.X, e.Y).Type == DataGridViewHitTestType.ColumnHeader)
{
new ContextMenuStrip().Show(dataGrid, e.Location);
}
}
}
See: How do I correctly position a Context Menu when I right click a DataGridView's column header?
Upvotes: 1