1

I am facing some strange issue in datagridview.I have datagridview with ComboBox Column.I have used datagridviewv_EditingControlShowing event and then use GridCombo_SelectedIndexChanged event.First time when i select some Disply Member from Combobox there is no issue.But after that Its color change like Black & Blue.So Display Members not showing.Please check screenshot for more details.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;
        }
    }`
Hetvi
  • 132
  • 1
  • 1
  • 8
  • [http://stackoverflow.com/questions/7242308/to-change-the-datagridviewcomboboxcell-colorstyle-dynamically](http://stackoverflow.com/questions/7242308/to-change-the-datagridviewcomboboxcell-colorstyle-dynamically) – Eminem Apr 22 '15 at 08:19
  • Can you provide the code you are using to display this `DataGridView` – hynsey Apr 22 '15 at 08:23
  • Try this http://stackoverflow.com/questions/13829621/bindingsource-with-datagridview-combo-box – Pradnya Bolli Apr 22 '15 at 09:42
  • Pradnya Bolli ...I don't need this..I am asking why color of combo box has been changing..?? – Hetvi Apr 22 '15 at 13:57
  • I have the same thing: Using the EditingControlShowing event to create the SelectedIndexChangedEvent. Just looking at the EditedFormattedValue property in the SelectedIndexChanged eventhandler means that when I use another ComboBoxCell on the DataGridView (same row different column or different row any column), the dropdown background turns black. Very strange. – Michael Aug 14 '15 at 11:09

1 Answers1

0

I have got round (not solved) the problem by avoiding the EditingControlShowing event and using the CurrentCellDirtyStateChanged event to commit the value straight away, then using CellValueChanged event with Value instead of EditedFormattedValue. See Severun's answer to this question which helped me solve my problem.

Community
  • 1
  • 1
Michael
  • 412
  • 3
  • 12