应用程序启动时DataGridViewComboBoxCell显示正常

选择该值后,当前行和后续行上的背景将变为黑色(见下文)。我使用了默认的DataGridView,没有字体操作

我尝试过在CellFormatting和CellMouseClick事件中更改颜色。但仍然是同样的行为。有什么想法吗?
发布于 2012-11-29 10:42:23
显然,这是一个记录在案的DataGridViewComboBoxColumn错误。Link with solution and workaround
发布于 2021-02-09 05:20:01
C#:DataGridViewComboBoxColumn下拉菜单全黑2010年12月20日-尼克·奥尔森
我今天在使用DataGridView时遇到了一个问题,其中一个定义为DataGridViewComboBoxColumn的列显示为完全黑色的下拉菜单,如下所示。
经过一些研究,我发现在DataGridViewComboBoxColumn中有一个记录在案的错误,在处理DataGridView的EditingControlShowing事件时有时会发生这种情况。我处理这个事件是为了连接嵌入在DataGridView单元格中的ComboBox的SelectedIndexChanged事件。
在错误报告中,微软声明他们不会修复这个错误,但谢天谢地,Debanjan1已经发布了解决这个问题的方法。如果您只需在EditingControlShowing事件中将CellStyle.BackColor属性设置为DataGridView.DefaultCellStyle.BackColor,问题就会消失。如下所示。
private void dataGridViewGLEntries_EditingControlShowing(object发送者,DataGridViewEditingControlShowingEventArgs e) { ComboBox cmbBx = e.Control as ComboBox;
if (cmbBx != null)
{
cmbBx.SelectedIndexChanged -= ComboBoxCell_SelectedIndexChanged;
cmbBx.SelectedIndexChanged += ComboBoxCell_SelectedIndexChanged;
// Fix the black background on the drop down menu
e.CellStyle.BackColor = this.dataGridViewGLEntries.DefaultCellStyle.BackColor;
}}
https://stackoverflow.com/questions/13557046
复制相似问题