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 Telerik.Windows.Controls.GridView;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;

namespace Hierarchy_WPF
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
			DataContext = (from i in Enumerable.Range(0, 5)
						  select new MyObject()
						  {
							  ID = i,
							  Name = String.Format("Name{0}", i),
							  Level = 1
						  }).ToList();  
		}		

		private void RadGridView1_RowLoaded(object sender, RowLoadedEventArgs e)
		{
			GridViewRow row = e.Row as GridViewRow;
			
			MyObject rowItem = e.DataElement as MyObject;
			
			if (row != null && rowItem != null)
			{
				if (rowItem.Items.Count<MyObject>() > 0)
					row.IsExpandable = true;
				else
					row.IsExpandable = false;
			}
		} 
	}  
}
