Completed
Last Updated: 06 Jun 2022 09:31 by ADMIN
Release R2 2022 (LIB 2022.2.606)
Suresh
Created on: 22 Apr 2022 08:57
Category: GridView
Type: Bug Report
0
RadGridView: NullReferenceException occurs while in edit mode the user scrolls and the validation fails with a messagebox

Use the following code: 

        public RadForm1()
        {
            InitializeComponent();

            DataTable dt = new DataTable();
            dt.Columns.Add("Id");
            dt.Columns.Add("Name");
            for (int i = 0; i < 10; i++)
            {
                dt.Rows.Add(i, "Item" + i); 
            }
            this.radGridView1.DataSource = dt; 
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; 
             
            this.radGridView1.CellValidating += radGridView1_CellValidating;
        }

        private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
        {
            if (e.Column.Index == 0 && e.ActiveEditor != null && e.Value + "" == "1")
            { 
                e.Cancel = true;
                RadMessageBox.Show("IncorrectValue");
            }
        }

Follow the steps:

1. Scroll to the last row.

2. Enter value "1" in the first cell of the last row

3. Click the area above the scrollbar's thumb to trigger scrolling to the top. You will notice that the message box will be shown and the view will be scrolled. Once the message is closed, the error occurs.

Workaround: 

        public class CustomGridView : RadGridView
        {
            public override string ThemeClassName  
            { 
                get 
                { 
                    return typeof(RadGridView).FullName;  
                }
            }

            protected override void OnMouseDown(MouseEventArgs e)
            {
             RadScrollBarElement scrollbar=   this.GridViewElement.ElementTree.GetElementAtPoint ( e.Location) as RadScrollBarElement;
             if (scrollbar!=null && this.IsInEditMode)
             {
                    this.EditorManager.CloseEditorWhenValidationFails = false;
                    this.EditorManager.CloseEditor();
                    return;
             }
                base.OnMouseDown(e);
            }
        }

 

 

0 comments