title: C# - DatagridView and ContextMenu
body: <p>I have a datagridview where I show infomation about products. I want to bind a contextmenu when the user selects a cell and then right clicks on that cell. I have another contextmenu and that one is bound to the columns of the datagridview. If a user right clicks on a column the contextmenu shows. </p>
  
  <p>I have tried like this but it does not work. The context menu shows when the user right clicks on a cell, but the contextmenu that is bound to the column header does not work. </p>
  
  <pre><code>   private void GridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
      {
          if (e.Button == MouseButtons.Right)
          {
              productContextMenu.Show(GridView1, e.Location);
          }
  
      }
  </code></pre>
  
  <p>How do I make it so that when the user right clicks on a datagridview shows up?</p>
  
  <p>Many thanx in advance.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thnx for the answers. I solved the problem like this:</p>
  
  <pre><code>    private void GridView1_MouseUp(object sender, MouseEventArgs e)
      {
          DataGridView.HitTestInfo hitTestInfo;
          if (e.Button == MouseButtons.Right)
          {
              hitTestInfo = GridView1.HitTest(e.X, e.Y);
              if (hitTestInfo.Type == DataGridViewHitTestType.Cell)
              {
                  productContextMenu.Show(GridView1, e.Location);
              }
  
          }
      }
  </code></pre>
  
  <p>Both the contextmenus shows. When I click on the column that context menu shows, and when I click on a cell that contextmenu shows.</p>