Completed
Last Updated: 27 May 2015 08:07 by ADMIN
ADMIN
Anton
Created on: 12 Apr 2013 05:46
Category: GridView
Type: Bug Report
5
FIX. RadGridView - current row changes even when canceling the RowValidating event.
RadGridView - current row changes even when canceling the RowValidating event.

Code to reproduce:
            public Form1()
            {
                InitializeComponent();

                radGridView1.AutoGenerateColumns = false;
                radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

                radGridView1.Columns.Add(new GridViewTextBoxColumn("A", "A"));
                radGridView1.Columns.Add(new GridViewTextBoxColumn("B", "B"));
                radGridView1.Columns.Add(new GridViewTextBoxColumn("C", "C"));

                radGridView1.Rows.Add("A", "AA", "AAA");
                radGridView1.Rows.Add("B", "BB", "BBB");
                radGridView1.Rows.Add("C", "CC", "CCC");
                radGridView1.Rows.Add("D", "DD", "DDD");
                radGridView1.Rows.Add("E", "EE", "EEE");
                radGridView1.Rows.Add("F", "FF", "FFF");
                radGridView1.Rows.Add("G", "GG", "GGG");

                radGridView1.RowValidating += new RowValidatingEventHandler(radGridView1_RowValidating);

            }

            void radGridView1_RowValidating(object sender, RowValidatingEventArgs e)
            {
                if (e.Row.Cells["B"].Value.ToString() == "BB")
                {
                    e.Cancel = true;
                }
            }


Steps to reproduce: 

1. Go to cell with value "BB"
2. NOT in edit mode press down arrow key 2-3 times
3. Change text to "AA"
4. Press Tab several times

Work around: 
Use custom navigator:

radGridView1.GridViewElement.Navigator = new MyGridNavigator();


            public class MyGridNavigator : BaseGridNavigator
            {
                private static readonly FieldInfo EnumeratorFieldInfo = typeof(BaseGridNavigator).GetField("enumerator", BindingFlags.NonPublic | BindingFlags.Instance);

                protected GridTraverser enumerator
                {
                    get { return EnumeratorFieldInfo.GetValue(this) as GridTraverser; }
                }

                protected override bool SelectCore(GridViewRowInfo row, GridViewColumn column)
                {
                    bool result = base.SelectCore(row, column);

                    if (!result)
                    {
                        enumerator.GoToRow(this.GridViewElement.CurrentRow);
                    }

                    return result;
                }
            }
0 comments