1

I have a DataGridViewComboBoxColumn that triggers an event on cell click, which ends up displaying a Dialog Box. This works great, but my problem is that I want this to only trigger if the user did NOT click on the arrow to display the dropdown. Right now there is no differentiation between a click on the text & on this arrow. How do I make this distinction? (I am aware of the CellContentClick event, but this can take an obnoxious number of clicks to actually trigger.)

enter image description here

(In my amazing illustration, I want green to trigger the event, and red just have its normal functionality.)

Carl Shiles
  • 434
  • 3
  • 15
  • Do you need to distinguish between the dropdown button area and text area, when the cell is in edit mode, or do you need it when the cell in not in edit mode? – Reza Aghaei Sep 29 '18 at 14:21
  • The cell is not selected before the click, so I suppose that would be not in edit mode. – Carl Shiles Sep 29 '18 at 15:03

2 Answers2

1

To detect if the mouse has been clicked on the dropdown button area in DataGridViewComboBoxCell, you can use the following code:

private void productsDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
    var field = typeof(DataGridViewComboBoxCell).GetField("mouseInDropDownButtonBounds",
        System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
    var mouseInDropDownButtonBounds = field.GetValue(null);
}

You can take a look at source code of DataGridViewComboBoxCell to find out more about how it calculates the dropdown button bound.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • Thats it! Thanks so much. It would be nice if it worked the same when the cell was already selected, but this is all I really need. – Carl Shiles Sep 29 '18 at 16:47
  • You're welcome. When the cell is in edit mode, what you see is a real `ComboBox`. While when it's not in edit mode, it's just a painting of a combo box. – Reza Aghaei Sep 29 '18 at 16:52
0

You can use the EditingControlShowing event:

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e){
    if (e.Control.GetType() == typeof(DataGridViewComboBoxEditingControl)){
        //The green is clicked

   }
}