using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;

namespace _1167997GridScrollToRow
{
    public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent(); 

            this.radGridView1.MouseUp += radGridView1_MouseUp;
        }
         

        private void radGridView1_MouseUp(object sender, MouseEventArgs e)
        {
            GridCellElement cell = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridCellElement;
            if (cell != null)
            {
                if (cell.RowInfo.Index % 2 == 0)
                {
                    DialogResult result = RadMessageBox.Show("You have unsaved data" + Environment.NewLine + "are you sure you want to continue?",
                        "Warning Message", MessageBoxButtons.OKCancel);
                    if (result == DialogResult.OK)
                    {
                        this.radGridView1.CurrentRowChanging -= radGridView1_CurrentRowChanging; 
                        this.radGridView1.CurrentRow = lastCurrent;
                        this.radGridView1.CurrentRowChanging += radGridView1_CurrentRowChanging; 
                        this.radGridView1.TableElement.ScrollToRow(lastCurrent);
                        lastCurrent = null;
                    }
                }
            }
        }

        GridViewRowInfo lastCurrent = null;

        private void radGridView1_CurrentRowChanging(object sender, Telerik.WinControls.UI.CurrentRowChangingEventArgs e)
        {
            lastCurrent = e.CurrentRow;
        }

        private void RadForm1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'nwindDataSet.Products' table. You can move, or remove it, as needed.
            this.productsTableAdapter.Fill(this.nwindDataSet.Products);
            
            this.radGridView1.CurrentRowChanging += radGridView1_CurrentRowChanging; 
        }
    }
}