using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;
using Telerik.Windows.Controls.GridView;

namespace TabKey_InsertRow
{
	public partial class MainPage : UserControl
	{
		public MainPage()
		{
			InitializeComponent();

			gridView.ItemsSource = Person.GetPeople(20);
			
			gridView.BeginningEdit += new EventHandler<GridViewBeginningEditRoutedEventArgs>(gridView_BeginningEdit);
			gridView.KeyDown += new KeyEventHandler(gridView_KeyDown);
		}

		public bool editFirstCell = false;

		void gridView_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e)
		{
			if (editFirstCell)
			{
				var row = e.Row;
				e.Cancel = true;
				(row.Cells[0] as GridViewCell).IsInEditMode = true;
				editFirstCell = false;
			}
		}

		void gridView_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.Key == Key.Tab)
			{
				editFirstCell = true;
				gridView.BeginInsert();
		
			}
		}
	}
}
