DevExpress控件使用交流,DevExpress中国社区 售前咨询
当前位置: 首页 > 开发资源 » 示例代码 » DevExpress XtraGrid网格控件示例五:验证终端用户输入的数据

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

作者:zhuhm   来源:本站原创   浏览:Loading...次   发布时间:2012-10-19   评论:0条

本示例中禁用了无效的“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
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [http://www.devexpresscn.com/]
本文地址:http://www.devexpresscn.com/Resources/CodeExamples-289.html

评论列表

暂无评论

请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!

昵称 不填则默认为游客评论

DevExpress DXperience DXv2 v12

DevExpress DXperience 下载 download

DevExpress购买、价格、授权

慧都控件网为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。

电话:400-700-1020
        023-66090381

邮箱:sales@evget.com

>>如何选择正规控件购买渠道