This question is locked. New answers and comments are not allowed.
Hi,
My collection contains ID and ParentID fields, I have to show hierarchal grid based on self reference of ID and ParentID with selected columns for parent and child grids. The same I have achieved from code behind using RadGridView.ChildTableDefinitions and GridView_DataLoading event, but now instead of generating child grid column at run time in dataloading event I want to fix these columns in xaml itself. I have tried many ways but HierarchyChildTemplate is not showing any data since I am unable to define its data source. Please find the following code:
XAML Code:
ViewModel Code:
Please let me know how I can achieve this functionality.
Thanks,
Pushpendra
My collection contains ID and ParentID fields, I have to show hierarchal grid based on self reference of ID and ParentID with selected columns for parent and child grids. The same I have achieved from code behind using RadGridView.ChildTableDefinitions and GridView_DataLoading event, but now instead of generating child grid column at run time in dataloading event I want to fix these columns in xaml itself. I have tried many ways but HierarchyChildTemplate is not showing any data since I am unable to define its data source. Please find the following code:
XAML Code:
<radGrid:RadGridView ItemsSource="{Binding EmployeeList}" AllowDrop="True" IsReadOnly="False" Style="{StaticResource CommonGridStyle}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" > <radGrid:RadGridView.Columns> <radGrid:GridViewDataColumn Header="ID" DataMemberBinding="{Binding ID}" IsReadOnly="True" /> <radGrid:GridViewDataColumn Header="Role" DataMemberBinding="{Binding Role}" IsReadOnly="True" /> <radGrid:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" IsReadOnly="True" /> <radGrid:GridViewDataColumn Header="Parent ID" DataMemberBinding="{Binding ParentID}" IsReadOnly="True" /> </radGrid:RadGridView.Columns> <telerik:RadGridView.ChildTableDefinitions> <telerik:GridViewTableDefinition> <telerik:GridViewTableDefinition.Relation> <telerik:TableRelation IsSelfReference="True"> <telerik:TableRelation.FieldNames> <telerik:FieldDescriptorNamePair ParentFieldDescriptorName="ID" ChildFieldDescriptorName="ParentID" /> </telerik:TableRelation.FieldNames> </telerik:TableRelation> </telerik:GridViewTableDefinition.Relation> </telerik:GridViewTableDefinition> </telerik:RadGridView.ChildTableDefinitions> <telerik:RadGridView.HierarchyChildTemplate> <DataTemplate> <telerik:RadGridView Name="childGrid" ShowGroupPanel="False" > <radGrid:RadGridView.Columns> <radGrid:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" IsReadOnly="True" /> <radGrid:GridViewDataColumn Header="Role" DataMemberBinding="{Binding Role}" IsReadOnly="True" /> </radGrid:RadGridView.Columns> </telerik:RadGridView> </DataTemplate> </telerik:RadGridView.HierarchyChildTemplate> </radGrid:RadGridView>ViewModel Code:
public class MainPageViewModel : INotifyPropertyChanged { private ObservableCollection<Employee> employeeList; public ObservableCollection<Employee> EmployeeList { get { return employeeList; } set { employeeList = value; OnPropertyChanged("EmployeeList"); } } public MainPageViewModel(MainPage view) { view.DataContext = this; GetEmployeeList(); } private void GetEmployeeList() { EmployeeList = new ObservableCollection<Employee>(); EmployeeList.Add(new Employee() { ID = 1, Role = "Supervisor", Name = "S 1", ParentID = 0 }); EmployeeList.Add(new Employee() { ID = 2, Role = "Worker", Name = "W 1", ParentID = 1 }); EmployeeList.Add(new Employee() { ID = 3, Role = "Supervisor", Name = "S 2", ParentID = 0 }); EmployeeList.Add(new Employee() { ID = 4, Role = "Worker", Name = "W 2", ParentID = 3 }); EmployeeList.Add(new Employee() { ID = 5, Role = "Worker", Name = "W 3", ParentID = 3 }); EmployeeList.Add(new Employee() { ID = 6, Role = "Supervisor", Name = "S 3", ParentID = 0 }); } #region Property Change public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler pceh = PropertyChanged; if (pceh != null) { pceh(this, new PropertyChangedEventArgs(propertyName)); } } #endregion Property Change } public class Employee { public int ID { get; set; } public string Role { get; set; } public string Name { get; set; } public int ParentID { get; set; } }Please let me know how I can achieve this functionality.
Thanks,
Pushpendra