2024年终活动

DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

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

来源:本站原创   发布时间:2012-10-19   浏览:4199次

本示例中禁用了无效的“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控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/389.html
扫码咨询
电话咨询
023-68661681
返回
顶部