觸發(fā)此事件時(shí),編輯器的內(nèi)容尚未應(yīng)用于表格。您可以驗(yàn)證編輯器內(nèi)容,并在必要時(shí)取消編輯。要驗(yàn)證編輯器內(nèi)容,請檢查編輯器中包含的BaseGrid.Editor.Text屬性值。如果該值對于單元格無效,請將Cancel參數(shù)設(shè)置為true,網(wǎng)格將保持編輯模式,直到用戶鍵入有效條目。例如,下面的代碼檢查以確保輸入的值是0到50之間的整數(shù)
Vb.Net |
Public Sub SmGrid1_ValidateEdit(sender As Object,e As C1.Win.C1FlexGrid.ValidateEditEventArgs) Dim tbl As SmGrid=sender '我們可以依據(jù)行列信息進(jìn)而獲得 Dim strColName As String=tbl.Cols(intCol).Name If strColName="分?jǐn)?shù)" Then Dim intScote As Integer If Integer.TryParse(tbl.Editor.Text,intScote) Then If intScote>=0 AndAlso intScote<=50 Then Return '什么也不做,接受編輯 End If End If '如果數(shù)據(jù)轉(zhuǎn)化失敗,或者在規(guī)定范圍之外,則拒絕編輯 e.Cancel=True End If End Sub |
C# |
public void SmGrid1_ValidateEdit(object sender, C1.Win.C1FlexGrid.ValidateEditEventArgs e) { SmGrid tbl = sender as SmGrid; // 我們可以依據(jù)行列信息進(jìn)而獲得 string strColName = tbl.Cols[intCol].Name; if (strColName == "分?jǐn)?shù)") { int intScote; if (int.TryParse(tbl.Editor.Text, out intScote)) { if (intScote >= 0 && intScote <= 50) return;// 什么也不做,接受編輯 } // 如果數(shù)據(jù)轉(zhuǎn)化失敗,或者在規(guī)定范圍之外,則拒絕編輯 e.Cancel = true; } } |