Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

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

$
0
0

I'm 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 I'm testing for values of the columns and if any are null I'm 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");   <===== Doesn't get executed
                }
                break;
            case "1":


Viewing all articles
Browse latest Browse all 2535

Trending Articles