- Name (string)
- ID (int)
- ParentID (int)
and that linear list defines a hierarchy by referencing to itself (each person whoose ID (primary key) is equal to the ParentID (foreign key) of another person is parent of this other person.
In the telerik WPF Controls Examples showing the Self-Reference Hierarchy, the thing is, that this hierarchy is not a clean hierarchy tree, because elements of the first level (e.g. EmployeeID = 1) show up in the second level as well. I would need to build a tree like a family tree, where one Id can only occur in one place and nowhere else. One the other hand, it would be nice to have the tree in linear form as well, to see all persons at one glance.
Can someone give me a hint, how this can be done easily?
Thanks,
6 Answers, 1 is accepted
The behavior that you have seen in our online examples is by design. Still you can easily prevent such rows(with ParentID != 0) from appearing on the root level by creating a filter descriptor which would only allow rows with ParentID equal to 0.
<controls:RadGridView.FilterDescriptors>
<data:FilterDescriptor Member=
"ParentID"
Operator=
"IsEqualTo"
Value=
"0"
/>
</controls:RadGridView.FilterDescriptors>
May you please refer to this forum thread on the same topic?
I am not sure what do you mean on this statement: "it would be nice to have the tree in linear form as well, to see all persons at one glance. ". Do you mean to not have any headers for the child grid? It would be nice to send us a screenshot of how you imagine this linear form.
Best wishes,
Didie
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

I suppose the filter for the next level of the tree is "all person id with parentid is equal to the current id" ?
I have found another - not that elegant - but still simple and extensible solution for presenting a linear list as a hierarchy tree:
My ViewModel class gets an ObservableCollection<Person> property called "Root".
To my Person class I have added an ObservableCollection<Person> property called "Children".
The whole linear Person collection is stored in App.Current.Properties["AllPersons"] (this is the not so elegant part of the solution)
In the XAML file I define the GridView containing nested GridViews up to 4 levels using the following definitions
<
telerik:RadGridView
Name
=
"Level0Grid"
ItemsSource
=
"{Binding Root}"
ShowGroupPanel
=
"False"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.ChildTableDefinitions
>
<
telerik:GridViewTableDefinition
/>
</
telerik:RadGridView.ChildTableDefinitions
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Id}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding ParentId}"
/>
</
telerik:RadGridView.Columns
>
<
telerik:RadGridView.HierarchyChildTemplate
>
<
DataTemplate
>
<
telerik:RadGridView
Name
=
"Level1Grid"
ItemsSource
=
"{Binding Children}"
ShowGroupPanel
=
"True"
AutoGenerateColumns
=
"False"
<!-- next levels are the same as level1grid but columns differ ... -->
The Root property uses LINQ to return the person with the lowest ParentID from all persons
var
root_with_min_parentid = allpersons.Aggregate((curmin, x) => (x.ParentId < curmin.ParentId ? x : curmin));
ObservableCollection<Person> allpersons = (ObservableCollection<Person>)App.Current.Properties[
"AllPersons"
];
var children = allpersons.Where(child => child.ParentId ==
this
.Id);
Hence the UI layout still remains in XAML, and the partial Person class generated from WebService can be extented without harm...
But anyway, I will try the filter solution as well.
Regarding the doubt about having a nice simple list of persons to display alternatively, I think I will try a selector which just displays the root grid without filtering - so, the whole person list is shown in one gridview.
Thanks,
You guys and ladies at support really do a great job!
I am glad to hear that you have some ideas. If you have any more questions, please do not hesitate to contact us.
Didie
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

I happened to see this thread, as I was researching something else. Have you taken a look at the RadTreeListView? It works very well with Hierarchical structures, and sounds like it might be a little better fit for what your trying to do. If you have a good Hierarchical view model in place, many of the issues you see in the standard GridView are handled.
Just a suggestion, Good Luck.
Russell.

thanks for your suggestion, for my project, as far as I can see, there are the 2 design options:
- either take a treeview and tweek it to look like a grid (with many columns to edit)
- or make the gridview (with many columns to edit) look like a tree.
learning to handle only one beast is better than dealing with 2 of them...
Cheers,
Hermann

I will have a look into it, thanks again for pointing at it.
Hermann