彩票走势图

DevExpress XtraGrid网格控件示例五:验证终端用户输入的数据

原创|其它|编辑:郝浩|2012-10-19 17:39:19.000|阅读 1418 次

概述:本示例中禁用了无效的“colBudget”列单元格赋值。单元格值应该大于零且小于1,000,000。BaseView.ValidatingEditor事件处理检查输入值的有效性。如果出现无效的单元格赋值,BaseView.InvalidValueException事件会显示异常消息框。在这样情况下,调用GridView.HideEditor方法以便放弃所做的更改。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

本示例中禁用了无效的“colBudget”列单元格赋值。单元格值应该大于零且小于1,000,000。BaseView.ValidatingEditor事件处理检查输入值的有效性。如果出现无效的单元格赋值,BaseView.InvalidValueException事件会显示异常消息框。在这样情况下,调用GridView.HideEditor方法以便放弃所做的更改。

C#

using DevExpress.XtraEditors.Controls;
// ...
private void gridView1_ValidatingEditor(object sender, BaseContainerValidateEditorEventArgs e) {
if (gridView1.FocusedColumn.Name != "colBudget") return;
if ((Convert.ToInt32(e.Value) < 0) || (Convert.ToInt32(e.Value) > 1000000))
e.Valid = false;
}
private void gridView1_InvalidValueException(object sender, InvalidValueExceptionEventArgs e) {
e.ExceptionMode = ExceptionMode.DisplayError;
e.WindowCaption = "Input Error";
e.ErrorText = "The value should be greater than 0 and less than 1,000,000";
// Destroying the editor and discarding the changes made within the edited cell
gridView1.HideEditor();
}
VB
Imports DevExpress.XtraEditors.Controls
' ...
Private Sub GridView1_ValidatingEditor(ByVal sender As Object, _
ByVal e As BaseContainerValidateEditorEventArgs) Handles GridView1.ValidatingEditor
If GridView1.FocusedColumn.Name <> "colBudget" Then Exit Sub
If (Convert.ToInt32(e.Value) < 0) Or (Convert.ToInt32(e.Value) > 1000000) Then
e.Valid = False
End If
End Sub
Private Sub GridView1_InvalidValueException(ByVal sender As Object, _
ByVal e As ValidatingEditorEventArgs) Handles GridView1.InvalidValueException
e.ExceptionMode = ExceptionMode.DisplayError
e.WindowCaption = "Input Error"
e.WindowText = "The value should be greater than 0 and less than 1,000,000"
' Destroying the editor and discarding the changes made within the edited cell
GridView1.HideEditor()
End Sub



标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:DevExpress中文网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP