DataGridViewComboBoxColumn change events

  • Thread starter Thread starter B. Chernick
  • Start date Start date
B

B. Chernick

I have a Winforms app with a datagridview control (Dot Net 2.0) One column
is a bound combobox.

What I would like to do is if the combo box is changed to a certain value,
change the value of another cell in the same current row. What I have so far
is some code in the CurrentCellDirtyStateChanged event. This works, but the
event only fires when the cell with combobox is exited.

Is there a way to do this without leaving the combobox cell?

(So far every method I've tried has required leaving the cell and/or row.)
 
Chernick,

Can you please try the following code. Let me if its working you.
COLUMN_COMBO_SELECTION = your combo column id

private void dataGridView_CurrentCellDirtyStateChanged(object sender,
EventArgs e)

{

if( this.dataGridView.CurrentCell.ColumnIndex == COLUMN_COMBO_SELECTION) {

this.dataGridView.EndEdit();

}

private void dataGridView_CellValueChanged(object sender,
DataGridViewCellEventArgs e)

{

if (e.RowIndex != -1 && e.ColumnIndex == COLUMN_COMBO_SELECTION)

{

string comboText = this.dataGridView.CurrentCell.Value.ToString();

switch (comboText)

{

case "Text1":

this.dataGridView[COLUMN_NEXT, e.RowIndex].Value = "Default Text";

break;

}

}



Thanks

Jibesh
 
Back
Top