Previous topicNext topic
Help > 开发指南 > SanMuGrid平台编程 > 主要对象 > BaseGrid > 事件 >
ValidateEdit

触发此事件时,编辑器的内容尚未应用于表格。您可以验证编辑器内容,并在必要时取消编辑。要验证编辑器内容,请检查编辑器中包含的BaseGrid.Editor.Text属性值。如果该值对于单元格无效,请将Cancel参数设置为true,网格将保持编辑模式,直到用户键入有效条目。例如,下面的代码检查以确保输入的值是0到50之间的整数

Vb.Net
Public Sub SmGrid1_ValidateEdit(sender As Object,e As C1.Win.C1FlexGrid.ValidateEditEventArgs)
    Dim tbl As SmGrid=sender
    '我们可以依据行列信息进而获得
    Dim strColName As String=tbl.Cols(intCol).Name
    If strColName="分数" 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
        '如果数据转化失败,或者在规定范围之外,则拒绝编辑
        e.Cancel=True
    End If
End Sub

C#
public void SmGrid1_ValidateEdit(object sender, C1.Win.C1FlexGrid.ValidateEditEventArgs e)
{
    SmGrid tbl = sender as SmGrid;
    // 我们可以依据行列信息进而获得
    string strColName = tbl.Cols[intCol].Name;
    if (strColName == "分数")
    {
        int intScote;
        if (int.TryParse(tbl.Editor.Text, out intScote))
        {
            if (intScote >= 0 && intScote <= 50)
                return;// 什么也不做,接受编辑
        }
        // 如果数据转化失败,或者在规定范围之外,则拒绝编辑
        e.Cancel = true;
    }
}