原創(chuàng)|其它|編輯:郝浩|2012-10-19 17:39:19.000|閱讀 1445 次
概述:本示例中禁用了無效的“colBudget”列單元格賦值。單元格值應(yīng)該大于零且小于1,000,000。BaseView.ValidatingEditor事件處理檢查輸入值的有效性。如果出現(xiàn)無效的單元格賦值,BaseView.InvalidValueException事件會顯示異常消息框。在這樣情況下,調(diào)用GridView.HideEditor方法以便放棄所做的更改。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
本示例中禁用了無效的“colBudget”列單元格賦值。單元格值應(yīng)該大于零且小于1,000,000。BaseView.ValidatingEditor事件處理檢查輸入值的有效性。如果出現(xiàn)無效的單元格賦值,BaseView.InvalidValueException事件會顯示異常消息框。在這樣情況下,調(diào)用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(); }
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
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:DevExpress中文網(wǎng)