title: How to add ContextMenu in a particular DataGridViewCell? (C# winforms)
body: <p>I'm trying to add a <code>ContextMenu</code> in a particular cell of a <code>DataGridView</code>. Like the image below:</p>
  
  <p><img src="https://i.stack.imgur.com/N83Pw.png" alt="alt text"></p>
  
  <p>I found it very hard to do, but I did a it in a TextBox control using the below code:</p>
  
  <pre><code>private void Form1_Load(object sender, EventArgs e)
  {
      foreach (Control control in this.Controls)
      {
          // Add KeyDown event to each control in the form.
          control.KeyDown += new KeyEventHandler(control_KeyDown);            
      }
  }
  
  private void control_KeyDown(object sender, KeyEventArgs e)
  {
      Control ctrl = (Control)sender;
      if (e.KeyData == Keys.F1) // Check if F1 is being pressed.
      {
          if (ctrl.GetType() == typeOf(TextBox)) // Check if the control is a TextBox
          {
              ToolStripControlHost lblInfo;
              label1.Text = "This context menu is for TextBoxes.";
              lblInfo = new ToolStripControlHost(label1); // some Label 
              contextMenuStrip1.Items.Add(lblInfo);
              contextMenuStrip1.Show(ctrl, 0, 25); // Popups the contextMenu just below the textBox control.
          }
      }
  }
  </code></pre>
  
  <p>I just don't know how to do it in a particular cell of a DataGridView.
  I tried experimenting on this code:</p>
  
  <pre><code>if (ctrl.GetType() == typeOf(DataGridView)) // Check if the control is a DataGridView
  {
      DataGridViewCell testCell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentRow.Index]; // Returns DataGridViewCell type
  
      ToolStripControlHost lblInfo;
      label1.Text = "test";
      lblInfo = new ToolStripControlHost(label1); // some Label 
      contextMenuStrip1.Items.Add(lblInfo);
      contextMenuStrip1.Show(testCell, 0, 25);
  }
  </code></pre>
  
  <p>But i think ContextMenu only accepts a <code>Control</code> type on its first argument, and I got this exception: </p>
  
  <pre><code>cannot convert from 'System.Windows.Forms.DataGridViewCell' to 'System.Windows.Forms.Control'   
  </code></pre>
  
  <p>Are there any workaround on this? Please advice me what to do.. thanks in advance.</p>