Unplanned
Last Updated: 08 Jun 2022 07:52 by Suresh
Suresh
Created on: 08 Jun 2022 07:52
Category: GridView
Type: Bug Report
0
RadGridView: Editor is closed after clicking the vertical scrollbar when validation fails

Use the following code snippet:

        public RadForm1()
        {
            InitializeComponent();
            this.radGridView1.Columns.Add("TextColumn");
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

            for (int i = 0; i < 30; i++)
            {
                this.radGridView1.Rows.Add(Guid.NewGuid().ToString());
            }
            this.radGridView1.CellValidating += radGridView1_CellValidating;

            this.radGridView1.EditorManager.CloseEditorWhenValidationFails = false;
        }

        private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
        {
            if (e.Value == null || e.Value == "")
            {
                e.Cancel = true;
                RadMessageBox.Show("Value can't be empty!");
            }
        }

Steps:

1. Clear the value of a cell

2. While the editor is active with an empty value, click the vertical scrollbar to trigger scrolling.

Actual: the scrolling is performed and the editor is closed with the previous value no matter when the validation fails and the CloseEditorWhenValidationFails property is set to false.

Expected: the scrolling should be blocked if the validation fails. We should offer the same behavior when scrolling with the mouse wheel, clicking another cell or clicking the vertical scrollbar (or any of its elements).

Workaround: 

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

            protected override void OnMouseDown(MouseEventArgs e)
            {
                RadScrollBarElement scrollBarAtPoint = GetScrollbarElementAtPoint<RadScrollBarElement>(this.GridViewElement.ElementTree, e.Location) as RadScrollBarElement;
                GridViewEditManager editManager = this.EditorManager;
                if (scrollBarAtPoint != null && this.ActiveEditor != null && !editManager.CloseEditorWhenValidationFails)
                {
                    bool isClosed = editManager.CloseEditor();
                    if (!isClosed)
                    {
                        return;
                    }
                }
                base.OnMouseDown(e);
            }

            internal T GetScrollbarElementAtPoint<T>(RadElementTree componentTree, Point point) where T : RadElement
            {
                if (componentTree != null)
                {
                    RadElement elementUnderMouse = componentTree.GetElementAtPoint(point);

                    while (elementUnderMouse != null)
                    {
                        T item = elementUnderMouse as T;

                        if (item != null)
                        {
                            return item;
                        }

                        elementUnderMouse = elementUnderMouse.Parent;
                    }
                }

                return null;
            }
        }

 

 

0 comments