Where to put code that calls UnitOfWork::AddForDelete?

Posts   
 
    
Posts: 16
Joined: 22-Mar-2006
# Posted on: 25-Aug-2006 23:51:30   

[LLBLGen Pro 2.0, Self Servicing, SQL Server 2005]

I have some WinForms whose controls are data bound to the fields in an LLBLGen Pro entity, and which have the usual BindingSource and BindingNavigator. These particular forms don't use a grid, just individual textboxes and dropdown lists. I'm trying to implement delete using the button in the BindingNavigator.

I've looked through the forums here and found out about setting the AllowRemove property of the collection to true, calling AddForDelete on a UnitOfWork, etc, so I think I have a pretty good idea of what I need to do. What I'm not sure about is where to put the code that calls AddForDelete. I tried putting it in bindingNavigatorDeleteItem_Click, but that gets called after the item is removed from the collection, so the item is no longer around to pass to AddForDelete.

Where is the best place to put this code?

Thanks,

Wayne

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 27-Aug-2006 10:58:07   

Bind a handler to the collection's EntityRemoving event. simple_smile You then can grab the entity which is to be deleted from the eventargs. You can also cancel the event there. So you can also pop up a "Are you sure?" dialog if you want to. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 16
Joined: 22-Mar-2006
# Posted on: 29-Aug-2006 04:43:40   

Hi Frans,

I did as you suggested, and it works great! simple_smile The ability to put up the "Are you sure?" dialog is really useful.

Thanks!!!

Wayne