Hi,
I have a nested list of objects. I need the data to be displayed in hierarchial manner.
I have a list of objects, lets say list A, which has IList(of B) (Generic List) as one of its properties and IList(of B) contains IList (of C). What should i do to display the data in hierarchial way ?
Couple of tradeoffs that i have is, IList(of B) and IList(of C) might not have the same columns and i'm trying to use BindingList(of A). Still i get only parent list and not the child ones'
Any help is appreciated!
Thanks.,
If you have a list of A and one of the properties of the A object is a list of some other object, then you don't have to do anything. SImply bind the grid to the list of A objects and the B object list will display as a child band.
I would recommend using BindingList rather than List, though. List will not allow you to add new rows and it will not update the grid when the data changes.
Also, you might have to use List rather than just IList. It think the BindingManager might not recognize IList as a valid chaptered property.
OK, it works but up to level 2, I mean two bands are displayed.
How to make it work with any depth?
OK, I finally figured it out. The point is that BindingList<T> exposes property Items which has Add method.
However, the type of Items is IList<T> and adding new items in this way does not cause proper events to fire.
In particular, grid is not being updated. One has to use BindingList<T>.Add method ... .
If the rows aren't showing up in the grid, it's probably because your data source isn't notifying the grid that new rows have been added. List<T> is not a good data source for this, because it doesn't send the proper notifications.
You should use BindingList<T>, instead for both the main list and the Friends property.
Also, make sure the Friends property does not return null. It has to return an empty BindingList<T> or the BindingManager will not be able to get the data structure.
Let me elaborate on this problem a little.
Picture a form with a "Grid1" and two buttons: "btnAdd" and "btnGroup".
Form loads with a number of rows in the "Grid1"; grid has a single band at this stage.
Now, when one clicks "btnAdd" a new row is added to the top band, when one selects a bunch of rows and clicks "btnGroup" selected rows are removed from the top band and a new child band is created for them. Also, a new row is added to the parent band which signifies new group header. So now we have two bands. At this stage if user clicks on "btnAdd" new row is added to the band which is current (top band if there is no row selected). Still user can select a few rows within any either band and click "btnGroup" which would either create a new band (if selected rows where in the second band) or add new group to existing band.
Programmatically this can be expressed as a class "Friend" with two properties "Name" of type string and "Friends" which is List <Friend>. One can add a new friend and create groups of friends.
Now, back to Ultragrid. When binding such structure to grid everything works fine with first band. However, when I want to add new rows to second band (the one with index 1) the rows are not displayed. That is clicking "btnAdd" does add new row in proper place to the data source but new row in not visible on the grid. If I rebind grid to the data source rows are displayed so this seems to be grid's problem.
Of course rebinding collapses bands so i do not want to do this ... (unless there is a way to save grid's layout before rebinding and then reusing it after rebinding?)
I notice that this seems to be a known problem, see for example the last post at:
http://www.softfluent.com/forums/codefluent-entities/infragistics-ultrawingrid-addrow-does-not-add-row-to-collection#Y8WpcZV6UmCsBf8AAA-tbA
What do I miss?