I have a winforms app that uses a grid and can bind to a typed dataset and shows the hierachy just fine,
When I make a similar sample and set the grid datasource to the main entity framework object I get a redundant recursive hierachy starting at the connection.
If I set the datasource to the top level entity table, I see the proper hierarchy in the "add new" button and see the rows for this top level parent table but there are no child rows if I click the + sign on the parent row.
Using datasource binding and the UltraDataSource shows the proper hierachy in the "add new" button diagram but show no data at all and I can debug the entity tables and the data is present.
Any suggestions?
Thanks, Dave
Hi Dave,
What version of the grid are you using? Are you using the latest service release?
The project references says Infragistics2.Win.UltraWinGrid.v9.1 as the name and v2.0.50727 as the runtime version. Thanks, Dave
I submitted my example to Infragistics developer support. Hristo from that support team figured out the problem.
Again, my particular issue with bound hierarchical entity data was that the way I had things set up, new sub-rows added to the hierarchy after binding the list to the grid were not showing up. The .ResetBindings and .Refresh methods were not making the new sub-rows appear.
Hristo informed me that the mechanism UltraWinGrid uses to determine it must refresh the list, is to listen for the BindingList's "OnListChange" event. Since in my case, the new items were not being added to the BindingList itself, (they were being added to a collection of an object in the list) the BindingList doesn't know to raise the OnListChange event.
So, when binding the BindingList, UltraGrid is smart enough to traverse all sub-lists and create bands accordingly, but it had no way of knowing when a sub-list changed because BindingList doesn't raise an event to inform it. Hristo suggested two possible solutions:
1. modify my entity class so that the OnListChange event gets raised when sub-items are added to the child collection's of the objects in the list2. manually refresh the Band.Rows.Refresh method for the child band that just got a row added to it.
I went with 2. My code uses a button on a column of the parent-row that is set up as "ColumnStyle.Button". In the ClickCellButton event I can access the child band to refresh it as follows:
e.Cell.Row.ChildBands[
"Children"].Rows.Refresh(RefreshRow.ReloadData);
I was unaware of that little method in there. Thanks, Hristo.
Personally, it seems that the relationship between BindingList and UltraGrid could be improved so that changes to sub-lists that obviously had to be traversed to render them in the child bands can be tracked and auto-refreshed. But, being on the outside of those two black-boxes, I probably have no idea how difficult or possibly performance draining this might be.
Apologies for resurrecting an old thread but I'm looking to solve a similar issue. I have a hiearchical model and various views. My object, lets call it A contains a BindingList<A> as a property called Children. I can add an item to the Children and View one will update correctly, but my second view doesn't. I think it's because the second view is not listening for the ListChangedEvents. The views are setup as follows:
View 1 (BindingList<A>) containing Children of BindingList<A>
View 2 (BindingList<B>) containing Children of BindingList<A>
The main difference is the root objects in the top level BindingLists are different types, the children are the same though. Anyone any ideas what I could do to remedy this?
Regards,
Martin
Hi Martin,
I don't understand your question. What do you mean by "View"? Is that an EntityFramework thing? What does it have to do with the WinGrid?
Sorry for the confusion Mike.
The "Views" are actually WinGrids. View is my term for items in my apps presentation layer. Bascially I have Grid 1 bound to one BindingList and Grid 2 bound to the other. So it would look like this
Grid 1 bound to (BindingList<A>) containing Children of BindingList<A>
Grid 2 bound to (BindingList<B>) containing Children of BindingList<A>
After some reading I think because the grids are technically bound to different BindingSources there is no way for the children that are common in both hierarchies to notify other BindingSources that something has changed.
I hope that makes things clearer. Hopefully someone can shed some light on this.
Okay. I'm still a bit confused, though.
I think there might be a typo here:
Is that first line correct? Both parents and children are "A" objects?
Anyway... none of these lists have any connection to each other as far as I can see here. So adding a child row to any of these lists will have no effect on any other list. That has nothing to do with the grid, though. The grid won't show a new item because no new item exists.
Hi Mike,
It's a hard one for me to explain but I think you've got it. Basically I'm being given data via an object model which I'm putting into BindingLists. The problem is that although the data in Grid 1 and Grid 2 is the same at a given point in the hiearchies:
Grid 1 -> B->A1->A2 etc
Grid 2 -> A1->A2
the objects are different objects (checked with object.ReferenceEquals). So adding a new child item to A1 in Grid 2 won't be reflected in Grid 1. I'm thinking that I need to ensure that the data is mapped to an object only once. So then if A1 is the one and only A1 instance the changes should be reflected in both grids. I could be completely wrong though but off to do some more testing now.
Thanks for your reponses to date. They're helping me to clarify how the Binding is working.
Note for anyone reading: this is not an .NET Entity Data Model issue as my code is not using it.
I just went back and re-read your first post.
So you have an object "A" which has a property of BindingList<A>.
And you also have an object "B" which has a property of BindingList<A>.
You bind one grid to a BindingList<A> and another grid to a BindingList<B>.
Is that right?
So then you add a child row to the first grid and... that's where you lose me. How would this have any effect on the second grid? Any given "A" object in the root band of Grid 1 has it's own BindingList<A> which contains it's children. So adding an item to that BindingList cannot possibly have any effect on any child row of a B object. Unless your BindingList<A> property is settable and you are assigning the same collection to two different parents.
If that's the case, then my advise would be not to do that. Using the same object and binding it to two different BindingLists is dangerous and probably won't work right.