Did some additional investigation starting from the 'Self-Reference Hierarchy' example in the telerik UI for WPF Demos.
Instead of generating the data in code, we used a database to get our data from.
The only code we've added is the following code in the DataLoading function as we need more then 1 hierarchical level
void
RadGridView1_RowLoaded(
object
sender, RowLoadedEventArgs e)
{
GridViewRow row = e.Row
as
GridViewRow;
TblLstLocation employee = e.DataElement
as
TblLstLocation;
if
(row !=
null
&& employee !=
null
)
{
row.IsExpandable =
this
.HasSubordinates(employee);
}
}
private
bool
HasSubordinates(TblLstLocation employee)
{
return
(from emp
in
(IEnumerable<TblLstLocation>)
this
.RadGridView1.ItemsSource
where emp.UpperLocationID == employee.LocationID
select emp).Any();
}
private
void
RadGridView1_DataLoading(
object
sender, GridViewDataLoadingEventArgs e)
{
GridViewDataControl dataControl = (GridViewDataControl)sender;
if
(dataControl.ParentRow !=
null
)
{
dataControl.BorderThickness =
new
Thickness(0, 1, 0, 1);
dataControl.GridLinesVisibility = GridLinesVisibility.None;
dataControl.ShowGroupPanel =
false
;
dataControl.AutoGenerateColumns =
true
;
dataControl.CanUserFreezeColumns =
false
;
dataControl.IsReadOnly =
true
;
dataControl.ChildTableDefinitions.Clear();
TableRelation r =
new TableRelation();
r.IsSelfReference =
true
;
r.FieldNames.Add(
new
FieldDescriptorNamePair(
"LocationID"
,
"UpperLocationID"
));
dataControl.ChildTableDefinitions.Add(
new GridViewTableDefinition() { Relation = r });
//GridViewDataColumn column = new GridViewDataColumn();
//column.DataMemberBinding = new Binding("EmployeeID");
//dataControl.Columns.Add(column);
//column = new GridViewDataColumn();
//column.DataMemberBinding = new Binding("FirstName");
//dataControl.Columns.Add(column);
//column = new GridViewDataColumn();
//column.DataMemberBinding = new Binding("LastName");
//dataControl.Columns.Add(column);
//column = new GridViewDataColumn();
//column.DataMemberBinding = new Binding("Title");
//dataControl.Columns.Add(column);
}
}