Say I have a DataGridView in which I dynamically build up a ComboBox column and add values to it. What's the best approach to trapping when the user clicks on the drop down button to show the drop down list. If I simply use CellClick on the DataGridView, I get that event even if the user doesn't actually click on the drop down button.
So far what I've done is basically inherit from DataGridViewComboBoxCell and overrode the DropDownWidthProperty. In the getter I fire off a DropDown event. This works, but feels very "hacky". Any other suggestions?
using System;
using System.Windows.Forms;
public class DataGridViewEventComboBoxCell : DataGridViewComboBoxCell
{
private bool dropDownShown = false;
public event EventHandler BeforeDropDownShown;
private void OnBeforeDropDownShown()
{
if (this.BeforeDropDownShown != null)
{
this.BeforeDropDownShown(this, new EventArgs());
}
}
public override int DropDownWidth
{
get
{
if (!dropDownShown) //this boolean is here because I only need to trap it the very first time
{
this.OnBeforeDropDownShown();
dropDownShown = true;
}
return base.DropDownWidth;
}
set
{
base.DropDownWidth = value;
}
}
}