winform having bound combobox BindingSource Add reverts if no default value

  • Thread starter Thread starter Sushil Agarwal
  • Start date Start date
S

Sushil Agarwal

Guest
Dear experts,

today i ran into a problem that i had added a combobox on my winform which was bound to a field and due to busiiness logic that combobox was hidden on that instance



BindingNavigator1.BindingSource.AddNew();

after this line it was getting reverted , as one of the bound combo box was hidden and value assigned to it was null and no default value to this filed in beforeaddnew was given.

i want to know does there any method or way exist to notify that addnew has failed ?

i had no clue it is failing, but one of my experienced friend told to check assign defaultvalue to combobox fields then my problem got solved. but if no values are assigned is there a mechanism to know that addnew has failed/reverted ?

public void btntodo(int act)
{
switch (act)
{
case 1:
Todo = work.Add;
haserros = false;
ActionWhen();
if (BeforeAddnew != null)
{
BeforeAddnew();
}

BindingNavigator1.BindingSource.AddNew();
if (AfterAddnew != null)
{
AfterAddnew();
}

if (DetailTableRefresh != null)
{
DetailTableRefresh();
}
break;
case 2:
haserros = false;
if (BindingNavigator1.BindingSource.Position >= 0)
{
Todo = work.Edit;
ActionWhen();
if (AfterEdit != null)
{
AfterEdit();
}
if (DetailTableRefresh != null)
{
DetailTableRefresh();
}
}
break;
case 3:
haserros = false;
if (BindingNavigator1.BindingSource.Position >= 0)
{
Todo = work.Delete;
ActionWhen();
if (DetailTableRefresh != null)
{
DetailTableRefresh();
}
}
break;
case 4:
if (Todo == work.Delete)
{
//bool d_ok = true;
if (DialogResult.Yes == MessageBox.Show("Delete this record?", "Delete Record", MessageBoxButtons.YesNo))
{
if (BeforeDelete != null)
{
BeforeDelete();
}
BindingNavigator1.BindingSource.RemoveCurrent();
if (AfterDelete != null)
{
AfterDelete();
}
}
else
{
goto case 5;
}
}
if (BeforeUpdate != null)
BeforeUpdate();
if (haserros)
{
return;
}
if (tblUpdate != null)
{
tblUpdate();
}
if (btnTargetHit == true)
{
work currentToDo = Todo;
Todo = work.None;
ActionWhen();
if (AfterUpdate != null)
{
AfterUpdate(currentToDo);
haserros = false;
}
}
break;
case 5:
haserros = false;
if (tblRevert != null)
{
tblRevert();
}

Todo = work.None;
ActionWhen();
break;
case 6:
if (tblLocate != null)
{
tblLocate();
}

if (DetailTableRefresh != null)
{
DetailTableRefresh();
}

break;
case 7: //see
haserros = false;
Todo = work.See;
ActionWhen();
if (AfterSee != null)
{
AfterSee();
}
break;

}
}

Continue reading...
 
Back
Top