title: Why does my WinForms context menu not appear where the mouse is?
body: <p>In my application I have a <code>DataGridView</code> that is meant for configuring some options.  The idea is that you can enter whatever text you want in the first column, but if you right click it will give you explicitly supported values.  I need this to be a textbox rather than a dropdown list because I need to support editing invalid (or old) configurations.</p>
  
  <p>What I want is the user to right click in the field name column and have a context menu that is valid based on what type of configuration this is.  Therefore, I coded the following event</p>
  
  <pre><code>    private void grvFieldData_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
      {
          // If this is a right click on the Field name column, create a context menu 
          //   with recognized options for that field
          if (e.Button == MouseButtons.Right &amp;&amp; grvFieldData.Columns[e.ColumnIndex].Name == "clmFieldName")
          {
              ContextMenu menu = new ContextMenu();
  
              if (_supportedDataGrids.ContainsKey((cmbDataGrid.SelectedItem as DataGridFieldList).GridName))
              {
                  // Loop through all the fields and add them to the context menu
                  List&lt;string&gt; fields = _supportedDataGrids[((cmbDataGrid.SelectedItem as DataGridFieldList).GridName)];
                  fields.Sort();
  
                  foreach (string field in fields)
                      menu.MenuItems.Add(new MenuItem(field));
  
                  // Make sure there is at least one field before displaying the context menu
                  if (menu.MenuItems.Count &gt; 0)
                      menu.Show(this, e.Location, LeftRightAlignment.Right);
              }
          }
      }
  </code></pre>
  
  <p>This works "correctly", but the context menu is appearing at the top of the form, not where the mouse pointer is.  If I change the <code>Show()</code> call to use the <code>DataGridView</code> instead of the form, I have the same issue but instead it appears at the top-left hand corner of the grid, not where the mouse is.</p>
  
  <p>Oddly enough, if I change this event to a <code>MouseClick</code> event (instead of a <code>CellMouseclick</code> event) everything works and the context menu appears exactly where the mouse pointer is.  The problem with this option is that the user might not be right clicking on the cell that is currently selected, which means that when they click on a menu item, the selected cell will be changed and not the cell they right clicked on.  </p>
  
  <p>Does anyone have any hints why context menus created with the <code>CellMouseClick</code> are not showing at the correct spot?</p>