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.Data;
using Telerik.Windows.Controls;
using System.Threading;
using System.Windows.Markup;
using System.Globalization;
using System.Collections.ObjectModel;

namespace NewRowPosition
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Club previouslyEditedItem;

        public MainWindow()
        {
            
            InitializeComponent();
        }

        private void clubsGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
        {
            if (previouslyEditedItem != e.EditedItem)
            {
                Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                {

                    (this.clubsGrid.DataContext as MyViewModel).Clubs.Insert(0, new Club());
                    clubsGrid.CurrentCellInfo = new GridViewCellInfo(clubsGrid.Items[0], clubsGrid.Columns["Name"]);
                    clubsGrid.Focus();
                    clubsGrid.BeginEdit();
                    previouslyEditedItem = e.EditedItem as Club;
                    this.clubsGrid.NewRowPosition = Telerik.Windows.Controls.GridView.GridViewNewRowPosition.None;
                }));
            }
        }
    }
}
