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

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

        private void playersGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
        {
            ScrollIntoView(playersGrid, e.Row.Item);
        }

        private void ScrollIntoView(RadGridView grd, object itmSel)
        {
            grd.SelectedItem = itmSel;
            grd.ScrollIntoViewAsync(grd.SelectedItem, r =>
            {
                var row = r as GridViewRow;
                if (row != null)
                {
                    row.IsCurrent = true;
                    row.IsSelected = true;
                    row.Focus();
                }
                grd.CurrentItem = itmSel;
                grd.CurrentCellInfo = new GridViewCellInfo(grd.SelectedItem, grd.Columns[0]);
            });

        }

        private void playersGrid_AddingNewDataItem(object sender, GridViewAddingNewEventArgs e)
        {
            e.NewObject = new Player("sd", 6, Position.DF, "sdsd");
        }
    }
}
