datagridview组合框列表颜色变为黑色c#

时间:2015-09-12 08:00:37

标签: c# background-color datagridviewcombobox

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        int n = dataGridView1.CurrentCell.RowIndex;
        if (dataGridView1.CurrentCell.ColumnIndex == 0)
        {
            var cbCell = dataGridView1.Rows[n].Cells["category"] as DataGridViewComboBoxCell;
            DataTable dt = c1.ret("select category from category").Tables[0];
            cbCell.DataSource = dt;
            cbCell.ValueMember = "category";
            cbCell.DisplayMember = "category";
            cbCell.FlatStyle = FlatStyle.System;
        }
    }

我正在尝试为datagrid组合框设置数据源,但是当我设置数据源时。组合框颜色的下拉列表变成黑色。我已经尝试了一些代码来设置背景颜色,但是每个代码都失败了。现在我被我的项目困住了。请帮帮我....

1 个答案:

答案 0 :(得分:0)

您必须将默认颜色分配给组合框控件。

经过研究,我发现了solution,这要感谢尼克。

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    //your code....
     var cmbBx = e.Control as DataGridViewComboBoxEditingControl; // or your combobox control
     if (cmbBx != null)
     {
         // Fix the black background on the drop down menu
         e.CellStyle.BackColor = this.dgvSummary.DefaultCellStyle.BackColor;
     }
}