DataGridViewComboBoxColumn奇怪的行为

时间:2015-04-22 08:17:06

标签: c# winforms datagridview datagridcomboboxcolumn

我在datagridview中面临一些奇怪的问题。我有使用ComboBox Column的datagridview。我使用了datagridviewv_EditingControlShowing事件然后使用GridCombo_SelectedIndexChanged事件。第一次从Combobox中选择一些Disply Member时没有问题。但是之后它的颜色改变像Black& Blue.So显示会员未显示。请查看屏幕截图以获取更多详细信息。First time when SelectedIndexChanged event fire then it is ok.But from 2nd time when I want to change something inside combobox its color changing.

 private void datagridview_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if (e.Control is TextBox)
        {
            TextBox tb = e.Control as TextBox;
            if (flgCellEdit == true)
            {
                tb.KeyPress += new KeyPressEventHandler(NumericValidation_KeyPress);
                //tb.Leave += new EventHandler(GridTextBox_LeaveEvent);
            }
            else
            {
                tb.KeyPress += new KeyPressEventHandler(NumericValidationCancel_KeyPress);
            }
        }
        if (e.Control is ComboBox)
        {
            ComboBox comboBox = e.Control as ComboBox;
            switch ((sender as DataGridView).Name)
            {
                case "dgvIPO":
                    comboBox.SelectedIndexChanged += new EventHandler(GridCombo_SelectedIndexChanged);
                    break;

            }

        }
    } private void GridCombo_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataGridView dgv = (sender as DataGridViewComboBoxEditingControl).EditingControlDataGridView as DataGridView;
        DataGridViewRow dgvr = dgv.Rows[(sender as DataGridViewComboBoxEditingControl).EditingControlRowIndex];
        switch (dgv.Name)
        {

             case "dgvIPO":
                if (dgvr.Cells[5].EditedFormattedValue.ToString() == "N" && dgvr.Cells[6].EditedFormattedValue.ToString() == "N" && dgvr.Cells[7].EditedFormattedValue.ToString() == "N" && dgvr.Cells[8].EditedFormattedValue.ToString() == "N" && dgvr.Cells[9].EditedFormattedValue.ToString() == "N")
                {
                    dgvr.Cells[10].Value = "Complies";
                }
                else
                {
                    dgvr.Cells[10].Value = "Non Complies";
                }
                txtAcceptedQtySt1.Text = dgvIPO.Rows.Cast<DataGridViewRow>().Where(r => r.Cells[10].EditedFormattedValue.ToString() == "Complies").Count().ToString();
                break;
        }
    }`

0 个答案:

没有答案