本示例中禁用了无效的“colBudget”列单元格赋值。单元格值应该大于零且小于1,000,000。BaseView.ValidatingEditor事件处理检查输入值的有效性。如果出现无效的单元格赋值,BaseView.InvalidValueException事件会显示异常消息框。在这样情况下,调用GridView.HideEditor方法以便放弃所做的更改。
C#
1 using DevExpress.XtraEditors.Controls; 2 // ... 3 private void gridView1_ValidatingEditor(object sender, BaseContainerValidateEditorEventArgs e) { 4 if (gridView1.FocusedColumn.Name != "colBudget") return; 5 if ((Convert.ToInt32(e.Value) < 0) || (Convert.ToInt32(e.Value) > 1000000)) 6 e.Valid = false; 7 } 8 private void gridView1_InvalidValueException(object sender, InvalidValueExceptionEventArgs e) { 9 e.ExceptionMode = ExceptionMode.DisplayError;10 e.WindowCaption = "Input Error";11 e.ErrorText = "The value should be greater than 0 and less than 1,000,000";12 // Destroying the editor and discarding the changes made within the edited cell13 gridView1.HideEditor();14 }