【问题标题】:datagridview combobox list color changed to black c#datagridview组合框列表颜色更改为黑色c#
【发布时间】:2015-12-08 18:55:56
【问题描述】:
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 组合框设置数据源,但是当我设置数据源时。组合框颜色的下拉列表变为黑色。我尝试了一些设置背景颜色的代码,但每个代码都失败了。现在我被我的项目困住了。请帮帮我....

【问题讨论】:

    标签: c# background-color datagridviewcombobox


    【解决方案1】:

    您必须为组合框控件指定默认颜色。

    经过一番研究,我找到了solution,感谢 Nick。

    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;
         }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-03
      • 2021-09-03
      • 1970-01-01
      • 2017-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多