using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;

namespace MultipleChildDataInTabControl
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            GridViewTableDefinition detailDefinition = new GridViewTableDefinition();
            detailDefinition.Relation = new PropertyRelation("Orders");
            detailDefinition.Relation.Name = "Orders";
            this.radGridView1.TableDefinition.ChildTableDefinitions.Add(detailDefinition);
            this.radGridView1.TableDefinition.ChildTableDefinitions.Add(detailDefinition);
            this.radGridView1.ItemsSource = GetSampleHierarchy();
        }

        public static IList GetSampleHierarchy()
        {
            Func<int, List<Order>> ordersGen = customerIndex =>
            {
                var q = from i in Enumerable.Range(1, 10)
                        select new Order
                        {
                            ID = (10 * customerIndex) + i,
                            Description = "Order " + (10 * customerIndex + i)
                        };

                return q.ToList();
            };

            var t = from i in Enumerable.Range(1, 10)
                    select new Customer
                    {
                        Age = i,
                        JobCode = i,
                        Name = "Customer " + i,
                        Orders = ordersGen(i)
                    };

            return t.ToList();
        }
    }
}
