日期:2014-05-18  浏览次数:20938 次

datagridviewcomboboxcolumn 有时选择下拉时,背景色为什么变了颜色

我在下拉控件中加了此事件,目地是当我在第一个datagridviewcomboboxcolumn中选择某一个指定值 的时候,第二个datagridviewcomboboxcolumn 会自动选择第一个值,但两个框选来选去的时候 ,会出现,
如图的BUG http://hi.csdn.net/space-4312833-do-album-picid-914548-goto-down.html
,不知道怎么解决,请各们有劳了,谢谢!
C# code

        private void dgvVar_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.dgvVar.CurrentCell != null && this.dgvVar.CurrentCell.OwningColumn.Name == "colVarType")
            {
                ComboBox cb = e.Control as ComboBox;
                cb.SelectedIndexChanged += new EventHandler(FormIntelligenceDocument_SelectedIndexChanged);
            }
        }

        void FormIntelligenceDocument_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox cb = sender as ComboBox;
            if (cb != null)   
         {
                if (cb.Text == "其它字典")
                    this.dgvVar.CurrentRow.Cells["colVarZD"].Value = this._VarTypeZD.Rows[0]["Code"];
                else
                    this.dgvVar.CurrentRow.Cells["colVarZD"].Value = null;
                ////让变量类型失去焦点
                //this.dgvVar.EndEdit();

                //(sender as ComboBox).SelectedIndexChanged -= new EventHandler(FormIntelligenceDocument_SelectedIndexChanged);
            }
        }



------解决方案--------------------
楼主,你把每个可能设置背景色的地方,都检查一下:是不是人为设成了黑色!
BackgroundColor 、AlternatingRowsDefaultCellStyle 、ColumnHeadersBorderStyle 、ColumnHeadersDefaultCellStyle 、DefaultCellStyle
------解决方案--------------------
估计是某个属性设置问题
------解决方案--------------------
C# code


       private void dgvVar_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
cb.SelectedIndexChanged -= new EventHandler(FormIntelligenceDocument_SelectedIndexChanged);

            if (this.dgvVar.CurrentCell != null && this.dgvVar.CurrentCell.OwningColumn.Name == "colVarType")
            {
                ComboBox cb = e.Control as ComboBox;
                cb.SelectedIndexChanged += new EventHandler(FormIntelligenceDocument_SelectedIndexChanged);
            }
        }

------解决方案--------------------
探讨

就设置了这两个属性
dgvCbx.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
dgvCbx.FlatStyle = FlatStyle.Popup;