BO Status after DeleteOld forum URL: forums.lhotka.net/forums/t/4941.aspx
Warren posted on Thursday, June 05, 2008
In my Winforms app I delete a bank editable base object and am unsure of the best steps to take in my UI after a successful delete.
I delete the current record like this:
The sproc deletes the record and the record is still displayed in the form even though it no longer exists in the DB. My first thought was to re-load the form.
Should I be setting my object to nothing as in:
mbank = Nothing
In the debugger I see that mbank is still populated with the values from the deleted record.
I am curious as to what others are doing in this situation.
Thanks in advance.
SomeGuy replied on Thursday, June 05, 2008I would either close the form, or create a new Bank and rebind.
ajj3085 replied on Thursday, June 05, 2008Well, the object still exists and so behaves as a new object, with the values that WERE in the database. What to do is up to you.. maybe closing the form is appropriate? Moving to the next record?
For me most things that can be deleted are items in a grid... so deleted objects are off the grid (and eventually not referenced and GCed). The vast majority of my BOs though don't support delete, for history reasons. De-activating is the best you can do in my system for most BOs.
Warren replied on Thursday, June 05, 2008
I ended up clearing the form fields, deleteing the object, and calling ResetControlAuthorization to reset the form controls. The form remains displayed, the fields are disabled and cleared and the buttons are reset which is what I wanted.
The last piece of the 'plumbing' puzzle for me is to handle referential integrity issues. I'll create a new post for that though :-)
Thanks for the help.
jeff replied on Friday, June 06, 2008You could add a static event to the bank object like this:
public static event EventHandler<BankEventArgs> BankDeleted;
protected static void OnBankDeleted(BankEventArgs e)
EventHandler<BankEventArgs> handler = BankDeleted;
if (handler != null)
You would raise this event in your static DeleteBank method after the dataportal call. Now have your form subscribe to this event and check if its bank.Id = e.Bank.Id. If so, the form could close/reset itself.
Now, if you decide to allow bank deletion at other places in the UI you won't need any specific code there to handle this open form issue. You push the responsibility onto the form itself.
Copyright (c) Marimer LLC