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);
}
}