why can't I remove a row from VS2005 winforms grid readWrite entity collection?

Posts   
1  /  2  /  3
 
    
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39833
Joined: 17-Aug-2003
# Posted on: 21-Dec-2006 20:18:27   

You don't see the paperclip in hte post header of my previous post?

Frans Bouma | Lead developer LLBLGen Pro
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 21-Dec-2006 20:41:26   

sorry man,

yeah it's there. I'll start.

cheers,

yogi

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 22-Dec-2006 11:23:26   

morning simple_smile

Ok, in the NorthwindExampleCS that you attached, the winform that is most similar to mine is: "CustomerManager.cs"

<customerManagerGui> 1) combobox that displays customers..the combobox "drives" the databinding. 2) ordersDataGrid that displays orders, based on the current CUSTOMER. 3) orderDetailsDataGrid that displays order details, based on current ORDER.

Total 3x entities

</customerManagerGui>

Forget about my scenario for the moment.All I think I need to know is: "How to REMOVE individual products from "orderDetailsDataGrid"???

I do NOT, repeat NOT want to remove an entire order, simply an individual product.

eg, cutomer = BLAUS orderId = 10582

How can I remove the enire ROW from orderDetailsDataGrid, that contains productId 57? I converted it into a datagridView, but the "UserDeletingRow" event doesn't fire.

Why, in this example, can't I simply: 1) select an entire row 2) press the "DEL" button on my keyboard 3) have the "UserDeletingRow" event fire??

many thanks,

yogi

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 22-Dec-2006 16:49:38   

"How to REMOVE individual products from "orderDetailsDataGrid"???

The same logic that deletes an Order, can be applied to the OrderDetail. Please check the removeOrderButton_Click method that handles the Reomve Order button click.


UnbindOrders();
bool result = RemoveOrder(currentOrder);
if(result)
{
    MessageBox.Show(this, "The removal was succesful.", "Remove result.");
}
else
{
    MessageBox.Show(this, "The removal was NOT succesful.", "Remove result.");
}

DoRefresh();

Instead you will create your own methods -> UnbindOrderDetail & RemoveOrderDetail....etc

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 22-Dec-2006 17:01:06   

Walaa,

you've made the asumption that, in the NorthwindExampleCS sample, the "UserDeletingRow" event fires.

it doesn't, at least not for me.

I ask again

How can I remove the enire ROW from orderDetailsDataGrid, that contains productId 57? I converted it into a datagridView, but the "UserDeletingRow" event doesn't fire.

Why, in this example, can't I simply: 1) select an entire row 2) press the "DEL" button on my keyboard 3) have the "UserDeletingRow" event fire??

cheers,

yogi

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39833
Joined: 17-Aug-2003
# Posted on: 22-Dec-2006 19:29:14   

Ok, I'll spend one more try on this and then I'll close this thread. Please read the post below carefully, as it's important you read everything I explain below.

yogiberr wrote:

morning simple_smile

Ok, in the NorthwindExampleCS that you attached, the winform that is most similar to mine is: "CustomerManager.cs"

<customerManagerGui> 1) combobox that displays customers..the combobox "drives" the databinding. 2) ordersDataGrid that displays orders, based on the current CUSTOMER. 3) orderDetailsDataGrid that displays order details, based on current ORDER.

Total 3x entities

</customerManagerGui>

You can't create that in one go without coding. That's also why there's code in the form which binds the orderdetails.

The thing is: you have a master-detail-superdetail in this 3 -layer setup: master (customers) detail (orders) superdetail (order details).

The currencymanager on a form, can control a master and a detail, and keep them in sync. you do this in general by binding the collection to both grids, and set the datamember in the detail grid.

As you thus can see, you can't setup a superdetail with the same approach, as you then would have to bind the same collection also to the superdetail grid (thus customers again) and set the datamember to ... "orders.orderdetails", but that's not supported.

That's also why in the form, the orders and order details are bound manually and are bound to the orders collection. so the 'orders' is the master and orderdetails is the details. This leads to the fact that when an order is selected, the order details are selected automatically, by the currencymanager on the form.

Keyword is "in-sync": the currency manager on the forum has to keep everything in sync: what's selected in the master influences the details and what selected in the details influences the superdetails.

Because this SYNC problem is the ROOT CAUSE of finding which collection to set AllowRemove to true.

So when I take my example, and replace the Order details grid with a datagridview, and add this code to the BindOrders routine:

            foreach(OrderEntity order in _currentCustomer.Orders)
            {
                order.OrderDetails.AllowRemove = true;
            }

I can remove a row in the orderdetails by just pressing DEL. This is because I know which collection's to set allowRemove to true to. Though this is a pretty harsh loop. I also can bind an event handler to the Orders' grid event which is raised when I select a row. In there, I know which order is bound, as it's the entity object in the row. I then also know which collection to set the allowremove for, as that's the collection in that entity object.

I hope you'll understand that this is all winform databinding related material, not our code related material. You didnt post the bindingsource stack you used in your test with the example I gave you, so I can't rebuild that here.

Now, to get rid of this problem, you can also use a different approach, an include template which simply sets all contained entity collections in an entity's AllowRemove property to true. Also pretty harsh, as it doesnt' care about collection nor context the entity is used in, so perhaps not what you want.

So, without you and us losing any more time on this: I gave you an example, which allowed you to reproduce your problem. WHat I would like to ask you is to alter THAT example so it shows your problem and attach that example (just the GUI project, that's enough) to your reply. That will then allow us to see what's wrong, as this current track is going no-where as we keep on getting miscommunications back and forth and that just stalls your progress.

That example just contains northwind code, so it should be straight forward for us to reproduce the prob. (A problem which is solely about 'how to setup master-detail-superdetail databinding in winforms', i.e. a generic problem)

Frans Bouma | Lead developer LLBLGen Pro
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 23-Dec-2006 16:22:48   

right, I think it's solved.My scenario was even simpler, it was the equivalent of:

<customerManagerGui> 1) combobox that displays CUSTOMERS 2) ordersDataGrid that displays all orders, regardless of customer...this datagridView "drives" the databinding. 3) orderDetailsDataGrid that displays order details, based on current ORDER.

Total 3x entities. </customerManagerGui>

what I needed was: 1) user selects an order in the master datagridView 2) this slection is then reflected in both:

a) the current "customer " combobox b) the order details datagridView

This is the code I used for the UserDeletingRow event:


 private void orderDetailsDataGrid_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            OrderDetailsEntity orderDetailsItem = (OrderDetailsEntity)e.Row.DataBoundItem;

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

...maybe you might want to add it to your sample Frans.

As I say, I think it's solved. If I have any other hassles with it I can start a new, smaller post, based on the well known "CustomerManager" example.

Thanks for all the help folks, Now I hopefully have one less thing to do before Christmas.

All the best,

yogistuck_out_tongue_winking_eye

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 23-Dec-2006 23:51:55   

Glad you finally worked it out. simple_smile

1  /  2  /  3