user422481
user422481

Reputation: 49

BindingSource remove current

I use BindingSource for deleting records in my forms:

try
{
    BindingSource1.RemoveCurrent();
    BindingSource1.EndEdit();
    Table1TableAdapter.Update(dataSet01.Table1);
}
catch (Exception ex)
{
MessageBox.show(ex.Message);
}     

if record related to another,at first user see this record remove,but after that an error will arise. How can I prevent removing related record at first; so no error will be shown.

Upvotes: 0

Views: 11703

Answers (2)

Dome
Dome

Reputation: 59

try
{
    BindingSource1.RemoveCurrent();
    BindingSource1.EndEdit();
    Table1TableAdapter.Update(dataSet01.Table1);
    dataSet01.Table1.AcceptChanges(); <====== add this
}
catch (Exception ex)
{
MessageBox.show(ex.Message);
} 

Upvotes: 4

aleroot
aleroot

Reputation: 72636

You can for example load an hidden column in your grid that contains the reference to the related record, if the field is not null you have to implement the logic to avoid deletion of the record, and prevent the error.

Upvotes: 1

Related Questions