Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DataGridViewComboBoxColumn change events

10 views
Skip to first unread message

B. Chernick

unread,
Sep 25, 2008, 3:20:10 PM9/25/08
to
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.)

Jibesh

unread,
Oct 3, 2008, 6:43:30 AM10/3/08
to
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

"B. Chernick" <BChe...@discussions.microsoft.com> wrote in message
news:47A9A668-15A4-4946...@microsoft.com...

Daghan Karakasoglu

unread,
Nov 16, 2011, 9:04:41 AM11/16/11
to
it worked for me, thanks.
Here is the example;

private void dtg_tablo_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dtg_tablo.IsCurrentCellDirty)
{

dtg_tablo.CommitEdit(DataGridViewDataErrorContexts.Commit);
if (this.dtg_tablo.CurrentCell.ColumnIndex == 1)
{
this.dtg_tablo.EndEdit();
//DoWhatYouWant();
}
}
}

> On Thursday, September 25, 2008 3:20 PM BChernic wrote:

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


0 new messages