DataGridViewComboBoxColumn change events

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.)
 
J

Jibesh

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top