DataGridViewComboBox blacks out when using EditingControlShowing event

I have a DataGridView in C# windows application which uses .NET 2.0. The gridview has a combobox cell, two textbox cells. I have written EditingControlShowing event handler to add a SelectedIndexChanged event handler to the gridview combobox. The problem is: after one or two clicks, all cells get black background when focused. All combobox items when dropped down become black. When I comment out the event, this doesn't happen.  (I have  the same problem)/

 

HOW to solve this problem? Here is the answer.

private void dgvModelParam_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{ ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
// first remove event handler to keep from attaching multiple:
cb.SelectedIndexChanged -= new EventHandler(cb_SelectedIndexChanged);
// now attach the event handler
cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
cb.DropDown += new EventHandler(cb_DropDown);
}
}
void cb_DropDown(object sender, EventArgs e)
{
((ComboBox)sender).BackColor = Color.White;
}

你可能感兴趣的:(datagridview)