c# dgv when click away still triggers Context Menu
===

C# Winform project

I have a dataGridView with a contextMenu. Simply put everything is working as I want it to except it the context menu selection triggers even when I don't want it to (when I click away). 
For instance I right click on my dataGridView I see my selection. If I select it, it triggers a MouseClick event and does what I want. But if I click away it it sill triggers the MouseClick event.

I tried it in a OnMouseUp event in a few different ways but the same is happening. You'll notice a few extra "if's" in the code below which is basically me trying few things to get the MouseClick from triggering unecessarily (althogh in the end I believe it's just doing redundant work).

In code below please note below this: MessageBox.Show("something goes wrong here!");

Code:

    private void dgvMyDataGridView_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {
    	currentMouseOverCol = dgvMyDataGridView.HitTest(e.X, e.Y).ColumnIndex;
    	currentMouseOverRow = dgvMyDataGridView.HitTest(e.X, e.Y).RowIndex;
    
    	ContextMenu m = new ContextMenu();
    	if (currentMouseOverRow >= 0 && currentMouseOverCol == 1)
    	{
    		dgvMyDataGridView.CurrentRow.Cells[0].Value.ToString())));
    		m.MenuItems.Add(new MenuItem(string.Format("Do something with this row")));
    	}
    
    	m.Show(dgvMyDataGridView, new Point(e.X, e.Y));
    
        }
    
    
    
    
    	DataGridView.HitTestInfo hitTestInfo;
    	hitTestInfo = dgvMyDataGridView.HitTest(e.X, e.Y);
    
    	if (hitTestInfo.Type == DataGridViewHitTestType.Cell && hitTestInfo.ColumnIndex == 1 && currentMouseOverRow >= 0 && currentMouseOverCol == 1)
        {
    	MessageBox.Show("something goes wrong here!");
    	// Code to open a new form page - this all works.
    
        }
    }

What am I missing to tell my application to not trigger when I click away?

Thanks,

~ Chris


