Completed
Last Updated: 31 Mar 2014 10:10 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 26 Nov 2013 03:13
Category: GridView
Type: Bug Report
0
FIX. RadGridView does not manage correctly cancellation of the CellValidating event
To reproduce: 
-add RadGridView and use the following code: public Form1() { InitializeComponent(); radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; radGridView1.AddNewRowPosition = SystemRowPosition.Bottom; radGridView1.Columns.Add("A"); radGridView1.Columns.Add("B"); radGridView1.Columns.Add("C"); radGridView1.CellValidating += radGridView1_CellValidating; } void radGridView1_CellValidating(object sender, CellValidatingEventArgs e) { if ((string)e.Value == "11") { e.Cancel = true; } } Follow the steps: 1. First go to A and enter some value, hit TAB and go to B and enter some value. 2. Hit TAB and move to C. 3. Enter "11". 4. Hit TAB. Validation fails, but the new row is entered (calling radGridView1_RowValidating and ignoring e.Cancel = true; of radGridView1_CellValidating) 5. The erroneous value is copied to Column C in the new "new row". 6. radGridView1_CellValidating is called again.

Workaround: 
BaseGridBehavior gridBehavior = radGridView1.GridBehavior as BaseGridBehavior; gridBehavior.UnregisterBehavior(typeof(GridViewNewRowInfo)); gridBehavior.RegisterBehavior(typeof(GridViewNewRowInfo), new CustomGridNewRowBehavior()); public class CustomGridNewRowBehavior : GridNewRowBehavior { protected override bool ProcessTabKey(KeyEventArgs keys) { GridViewNewRowInfo newRowInfo = (GridViewNewRowInfo)this.GridViewElement.CurrentRow; if (newRowInfo.PinPosition == PinnedRowPosition.Bottom || newRowInfo.RowPosition == SystemRowPosition.Bottom) { FieldInfo fi = this.GridControl.GridBehavior.GetType().GetField("defaultRowBehavior", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); GridRowBehavior rowBehavior = fi.GetValue(this.GridControl.GridBehavior) as GridRowBehavior; MethodInfo mi = rowBehavior.GetType().GetMethod("ProcessTabKey", BindingFlags.NonPublic | BindingFlags.Instance); return (bool)mi.Invoke(rowBehavior, new object[] { keys }); } return base.ProcessTabKey(keys); } }
0 comments