CancelEdit() passes control which isn't desired. What else can I do?

  • Thread starter Thread starter Thom Ash
  • Start date Start date
T

Thom Ash

Guest
Im trying to add some bulletproofing in a DataGridView edit. Columns 0,1,2,3,& 4 must have values to comply with datatable primary keys as well as SQL table constraints. If any of the columns are blank I get either an internal exception on datatable primary keys or a SQL Exception on non nullable columns.

In the Leave Row event Im testing for values of the columns and if any are null Im calling CancelUpdate(). The problem is when CancelUpdate() executes it is passing control to the top of the event and starting over.

  1. Is this the correct behavior of CancelUpdate()?
  2. Given my stated goal, is there another way I can accomplish?

private void dgvVX130_LeaveRow(object sender, DataGridViewCellEventArgs e)
{
bool z = true; <======= CancelUpdate() passes execution to here
switch (dgvVX130.CurrentCell.ColumnIndex.ToString())
{
case "0":
if (dgvVX130.IsCurrentRowDirty && (dgvVX130.CurrentRow.Cells[1].Value.ToString() == "" || dgvVX130.CurrentRow.Cells[2].Value.ToString() == "" || dgvVX130.CurrentRow.Cells[3].Value.ToString() == ""))
{
z = false;
dgvVX130.CancelEdit(); <=== Passes execution to top of event
MessageBox.Show("You must have Database, Schema, and TableName defined before leaving row"); <===== Doesnt get executed
}
break;
case "1":

Continue reading...
 
Back
Top