下面的示例禁止指派无效的“Budget”列单元格取值。 此单元格的取值应大于 0,并且小于 1,000,000。 BaseView.ValidatingEditor 事件被接管,以检查输入值的有效性。 BaseView.InvalidValueException 事件被接管,如果指派了无效的单元格取值,则显示一个异常消息框。 在这种情况下 GridView.HideEditor 方法被调用,以放弃所作出的更改并销毁单元格的编辑器。
C# | 复制代码 |
---|
using DevExpress.XtraEditors.Controls;
private void gridView1_ValidatingEditor(object sender, ValidatingEditorEventArgs 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";
gridView1.HideEditor();
}
|
Visual Basic | 复制代码 |
---|
Imports DevExpress.XtraEditors.Controls
Private Sub GridView1_ValidatingEditor(ByVal sender As Object, _
ByVal e As ValidatingEditorEventArgs) 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"
GridView1.HideEditor()
End Sub
|