0

How can I trigger an event when the user opens a DataGridViewComboBoxCell to change their selection and they right click on one of the items listed? I would like to display a context menu when a user right clicks on certain items in the drop down.

I know in general how to display a context menu, I just can't figure out how to trigger an event when the user right clicks on the combobox when it's in edit mode (when the user is selecting items from the drop down)

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
JonF
  • 2,336
  • 6
  • 38
  • 57
  • Is this a real question? Its like GUI tautology - can you explain to us why you need to have a Popup Menu on a ComboBox (in a grid)? – Jeremy Thompson Mar 22 '12 at 01:15
  • I've found you the answer JonF, 'it is the second solution' in this Microsoft KB article: http://support.microsoft.com/kb/168702 but users have to hop on one leg rubbing the top of their head in a clockwise direction – Jeremy Thompson Mar 22 '12 at 21:18

1 Answers1

1
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)  
{  
    if (e.Button == MouseButtons.Right)  
    {  
        contextMenuStrip1.Show();  
    }  
}  

I'll explain how I did it in steps:

  1. Add Grid to form

  2. Add a ComboBox column to grid using RAD tools

  3. Set a datasource for the comboxColumn, eg

    Column1.DataSource = new string[] { "Location A", "Location B" };

  4. Add ContextMenu to form

  5. Add an item to the ContextMenu

  6. Set the Grids ContextMenuStip property to contextMenuStrip1

  7. Double click CellMouseClick - in the Grid Property Window Event List and add the code shown above:

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321