removing entityCollection row that is bound to datagridview

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 13-Mar-2006 22:00:02   

version 1.0.2005.1 final (self-servicing) VS2005 winforms


hiya,

Is it possible to remove an entityCollection row that is bound to datagridview, simply by using the "delete" button?

This behaviour is available thru standard winforms 2.0 RAD, can the same be done with an entityCollection?

cheers,

yogi

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 14-Mar-2006 02:11:17   

You will need to set the AllowRemove property for the collection to true. It will not delete the row from the database, but will remove it from the collection.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 15-Mar-2006 00:22:06   

hiya,

If that is the case, then If i call the "SaveMulti" method of the entityCollcetion, should the row should be removed fro the underlying database?

I have called the "SaveMulti" method in the datagridView_RowsRemoved event handler, but nothing happens.

How can I remove the row from the underlying database?

many thanks,

yogi

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 15-Mar-2006 03:30:49   

Take a look at this thread http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4944&HighLight=1. You will need to add the removed entities to either a collection or unit of work and commit the change when you want to remove them from the database using delete methods.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 16-Mar-2006 00:39:03   

hiya, Thanks for that.

I am struggling to see where this would fit in with a datagridView_RowsRemoved eventHandler....I can't see how I can grab the Id of the selected row from the event args.

This the code I have so far..far from complete but I am hoping that it can show where I am going wrong.


 private void dgvDeliveryProducts_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {


            //at the moment, I have hard-coded the args..but I have to somehow apply these args to the entityCollection
            TblDeliveryProductsEntity deliveryProductToBeDeleted = new TblDeliveryProductsEntity(0, "12344");
            
            
            UnitOfWork uow = new UnitOfWork();

            uow.AddForDelete(deliveryProductToBeDeleted);       
            uow.Commit(new Transaction(IsolationLevel.ReadCommitted, "UOW"), true);
            //ERROR: isolationLevel does not exist in this context.


Does anyone know why I get the "isloationLevel" error?

many thanks,

yogi

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Mar-2006 08:28:00   

I can grab the Id of the selected row from the event args.

I think you may the cells of your acted upon row by the following: e.Item.Cells[i]

For example if you have the id of you entity in the first cell then to get back the id you might use the following:

int nID = Int32.Parse(e.Item.Cells[0].Text);

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 16-Mar-2006 10:31:36   

ok thanks Walaa.

do youhave any idea why I am getting the "isolationLevel" error, I thought I had declared all the "using" statements that I need, but I can't find the one that contains "isolationLevel"

may thanks,

yogi

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Mar-2006 15:48:37   

Would you please post the complete exception stack trace?

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 19-Mar-2006 13:46:33   

hiya,

I needed to include the system.data namespace.

here's the code that worked. Thanks for the help,

yogi


private void dgvDeliveryProducts_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            object deliveryId = e.Row.Cells[0].Value;
            object productId = e.Row.Cells[1].Value;   

            TblDeliveryProductsEntity delivery = new TblDeliveryProductsEntity(deliveryId , productId );

            UnitOfWork uow = new UnitOfWork();
            uow.AddForDelete(delivery);
            uow.Commit(new Transaction(IsolationLevel.ReadCommitted, "UOW"), true);
        }

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 19-Mar-2006 17:12:56   

You may want to take a look at e.Row.DataBoundItem.

You could then cast e.Row.DataBoundItem to the EntityType contained in the collection bound to the grid.

Then you could have:


private void dgvDeliveryProducts_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            TblDeliveryProductsEntity delivery = (TblDeliveryProductsEntity) e.Row.DataBoundItem;

            UnitOfWork uow = new UnitOfWork();
            uow.AddForDelete(delivery);
            uow.Commit(new Transaction(IsolationLevel.ReadCommitted, "UOW"), true);
        }

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 21-Mar-2006 20:59:59   

cheers Jim, I like your style :-)

I had been trying to figure out how to cast and trim the cell values.

ta,

yogi