Hi
I have a hierarchical generic list which I would like to bind to a WinGrid.
I have:
A grouping class for my data List<GroupClass> gc
gc has a children property List<GroupClass> gc
So what i am trying to do is to bind this hierarchy to the WinGrid that would allow users to drill down the levels of the hierarchy.
This would be the first step.
The second is that there are actually 2 other classes. One that holds TIME in the exact same way as the group class: List<TimeClass> tc with children List<TimeClass>.
gc and tc have an infinte depth. for example the tc can have levels like 2009 > Quarter 1 > February > Day etc etc
The third class holds values. <List>ValueClass vc which has as properties gc.ID and tc.ID and a VALUE.
So i would like to be able to drill into the groups, then into the time for the groups down n number of levels to get the vc.VALUE.
Is something like this achievable, are there some pointers that you can give me to maybe get something close to what I am trying to achieve. Does this even make sense?
I understand how to bind data using a dataset and building datarelations. but i would like to bind my class with it's hierarchies directly.
Thanks
Hi,
If you are going to bind the grid to some custom objects like this, I recommend using BindingList<T>, rather than List<T>. BindingList is specifically designed for DataBinding and it will work better and send better notifications to the grid when data is added or removed from the list.
Regarding the rest of your question, you kinda lost me about half way through, so I'm not really clear on the data structure you want. But the way it works is that if you bind the grid to a List<T> or BindingList<T>, then each item in the list is a row in the grid and the properties of the object type <T> become the grid column.
To display child data, the object class <T> has to expose a public property that returns another List<T> or BindingList<T>.
Hi Mike
Mike Saltzman"] To display child data, the object class <T> has to expose a public property that returns another List<T> or BindingList<T>.
Could you please give me some sort of code sample for how you would do this.
Lets say my class is like this:
Class Test()
{
public string Name
public List<Test> Children
}
So basically i want to recursively bind this to the WinGrid.
So you click on the + symbol in the children column and it shows you a child grid nested inside the first grid. There is no limit to the depth of the hierarchy.
Thanks.
What you have here is correct. If you bind the grid to a List<Test>, you will get exactly what you are describing.