What is happening when I press ESC while editing a data-bound DataGridView?

  • Thread starter Thread starter nvx
  • Start date Start date
N

nvx

Hi,
could anyone please explain to me what exactly is happening when I
press ESC while editing a data-bound DataGridView?

The problem is I have a data-bound DataGridView and overriden
ProcessCmdKey function and when I press ESC, it produces DB column
constraint exception ("not null") for a column, which has not been
filled in yet.

I managed to find an ugly but working solution for a DGV with
DefaultView.RowFilter not set:
if (dSet.Tables["tblname"].Rows.Count == 0)
{
dSet.Tables["tblname"].Rows.Clear();
}
dataGridView.CancelEdit();

In case the DefaultView.RowFilter is set and DefaultView contains no
rows while the actual table contains one or more rows, I obviously can
not clear all rows of the DataTable and dataGridView.CancelEdit();
alone produces the above mentioned null-not-allowed exception. It is
all about getting rid of the detached row, I guess...

So, does anyone know what should I do when the RowFilter is set?

Thanks for any help...

With regards
nvx
 
I believe it does "Undo". So if you're editing a row, it undoes your
changes if you haven't moved to the next row yet.

Robin S.
 
Hi Robin,
thank you very much for your reply. I'm afraid this is not the exact
thing I need to know. I'd like to know the mechanism of cancelling the
edit, including the removal of detached row from DataGridView ("how
does the DGV do this itself", which code is responsible for this
action).

Nevertheless, thanks again for your time...

With regards
nvx


RobinS napsal:
I believe it does "Undo". So if you're editing a row, it undoes your
changes if you haven't moved to the next row yet.

Robin S.
---------------------------------
nvx said:
Hi,
could anyone please explain to me what exactly is happening when I
press ESC while editing a data-bound DataGridView?

The problem is I have a data-bound DataGridView and overriden
ProcessCmdKey function and when I press ESC, it produces DB column
constraint exception ("not null") for a column, which has not been
filled in yet.

I managed to find an ugly but working solution for a DGV with
DefaultView.RowFilter not set:
if (dSet.Tables["tblname"].Rows.Count == 0)
{
dSet.Tables["tblname"].Rows.Clear();
}
dataGridView.CancelEdit();

In case the DefaultView.RowFilter is set and DefaultView contains no
rows while the actual table contains one or more rows, I obviously can
not clear all rows of the DataTable and dataGridView.CancelEdit();
alone produces the above mentioned null-not-allowed exception. It is
all about getting rid of the detached row, I guess...

So, does anyone know what should I do when the RowFilter is set?

Thanks for any help...

With regards
nvx
 
I've done that when binding the DataGridView to a list of business objects,
but not with a datatable or dataset. I thought Esc just worked inherently.
Sorry.

Robin S.
-------------------------------
nvx said:
Hi Robin,
thank you very much for your reply. I'm afraid this is not the exact
thing I need to know. I'd like to know the mechanism of cancelling the
edit, including the removal of detached row from DataGridView ("how
does the DGV do this itself", which code is responsible for this
action).

Nevertheless, thanks again for your time...

With regards
nvx


RobinS napsal:
I believe it does "Undo". So if you're editing a row, it undoes your
changes if you haven't moved to the next row yet.

Robin S.
---------------------------------
nvx said:
Hi,
could anyone please explain to me what exactly is happening when I
press ESC while editing a data-bound DataGridView?

The problem is I have a data-bound DataGridView and overriden
ProcessCmdKey function and when I press ESC, it produces DB column
constraint exception ("not null") for a column, which has not been
filled in yet.

I managed to find an ugly but working solution for a DGV with
DefaultView.RowFilter not set:
if (dSet.Tables["tblname"].Rows.Count == 0)
{
dSet.Tables["tblname"].Rows.Clear();
}
dataGridView.CancelEdit();

In case the DefaultView.RowFilter is set and DefaultView contains no
rows while the actual table contains one or more rows, I obviously can
not clear all rows of the DataTable and dataGridView.CancelEdit();
alone produces the above mentioned null-not-allowed exception. It is
all about getting rid of the detached row, I guess...

So, does anyone know what should I do when the RowFilter is set?

Thanks for any help...

With regards
nvx
 
Back
Top