views:

19

answers:

0

I'm adding a new row to DGV DataGridGeneral, that is bound to BindingSourceGeneral. BindingSourceGeneral_CurrentItemChanged is run to save the row in the db. I try to launch RejectChanges() in case of error. BindingSource rejects the row properly, DGV rejects data, but 2!!! more rows appears in it! The coding:

private void BindingSourceGeneral_CurrentItemChanged(object sender, EventArgs e) { DataTable datatable = (System.Data.DataTable)((System.Windows.Forms.BindingSource)sender).DataSource; icompanyid = -1;

foreach (System.Data.DataRow datarow in datatable.Rows)
{
   System.Data.DataRowState drstate = datarow.RowState;

   switch (drstate)
   {
      case DataRowState.Added:
          if (icompanyid == -1)
          {
              datarow.RejectChanges();
              return; 
          }
          break;
       ...
   }

}

How can I get rid of these rows?