How to define HierarchyChildTemplate with Self Reference ChildTableDefinitions

3 posts, 0 answers
  1. Pushpendra
    Pushpendra avatar
    32 posts
    Member since:
    Nov 2012

    Posted 13 Feb 2013 Link to this post

    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:
    <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
  2. Nurlan
    Nurlan avatar
    2 posts
    Member since:
    Nov 2012

    Posted 08 Aug 2013 Link to this post

    Did you get a solution?
  3. DevCraft banner
  4. Pushpendra
    Pushpendra avatar
    32 posts
    Member since:
    Nov 2012

    Posted 26 Nov 2013 Link to this post

    Hi Nurlan,

    Sorry for the delay, but I have not found any solution for this.

    Pushpendra

Back to Top