using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Controls;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            this.DataContext = new NorthwindDataContext();
        }

        void RadGridView1_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            var row = e.Row as GridViewRow;
            if (row != null)
            {
                var customer = row.DataContext as Customer;
                if (customer.Orders.Count > 0)
                {
                    row.IsExpandable = true;
                }
                else
                {
                    row.IsExpandable = false;
                }
            }
        }

        private void RadGridView_Loaded(object sender, RoutedEventArgs e)
        {
            var dataControl = (GridViewDataControl) sender;
            var customer = dataControl.DataContext as Customer;
            dataControl.ItemsSource = customer.Orders;
        }
    }
}
