As previously noted I am implementing "AutoFilter" functionality in the
DataGridView, similar to that seen in Excel. This is done by inserting a row
of DataGridViewComboBoxCell objects at position zero in the grid and filling
each combo with a list of possible values for the Column in which it resides.
I have this working but I am not happy with my implementation. In order to
be able to detect a user change in filter conditions (which must be applied
to the displayed data immediately) I have attached a listener to
SelectedItemChanged of the ComboBox which is created within the
DataGridViewComboBoxCell when the cell enters edit mode, as follows:
private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
// snip...
// we must enter edit mode for the combo to be activated
dataGridView1.BeginEdit(false);
ComboBox comboBox = dataGridView1.EditingControl as ComboBox;
if (comboBox == null)
return;
// attach listener
comboBox.SelectedValueChanged += new
EventHandler(comboBox_SelectedValueChanged);
}
This is awkward and I have had to add a lot of other code to support it.
What I would prefer is to just capture changes to the underlying cell rather
than the ComboBox, but such changes are not available until the user moves
focus to another cell. Can anyone give me suggestions as to how I might do
this without having to listen to ComboBox events?
Many Thanks
kh
Luke Zhang [MSFT] - 27 Feb 2006 02:43 GMT
Hello,
I am not very clear about what you said about "just capture changes to the
underlying cell rather than the ComboBox". Why you need to capture changes
to the underlying cell since you want to capture user's selecttion the
combo box? Can you clarify more on this?
Thanks,
Luke Zhang
(This posting is provided "AS IS", with no warranties, and confers no
rights.)