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

此事件在控件进入编辑模式之前激发。它允许您通过将Cancel参数设置为true来防止编辑,或者重新设置BaseGrid.ComboList属性或重新设置BaseGrid.EditMask属性。

如果整列的选项或掩码相同,则可以使用BaseGrid.Cols("列名称").ComboList和BaseGrid.Cols("列名称").EditMask更有效地设置它们。在这种情况下,根本不需要处理StartEdit事件。

 VB.Net
'定义一个临时变量,存储上一个设置了错误信息的行
Private m_LastErrorRowData As RowData=Nothing
Public Sub StartEdit(sender As Object,e As  C1.Win.C1FlexGrid.RowColEventArgs)
    '获得当前表
    Dim tbl As SmGrid=sender
    '如果当前是绑定行
    If tbl.Rows(e.Row).DataIndex>=0 Then
        If tbl.Rows(e.Row)("Gender")="男" Then  '如果是男生,这里可以替换成自己的业务场景
            '如果之前有设置过错误信息,则在这里清空一下
            If m_LastErrorRowData IsNot Nothing Then
                m_LastErrorRowData.ClearErrors()
            End If
            '设置新的错误信息提示
            tbl.Rows(e.Row).GetRowData().SetError(tbl.Cols(e.Col).Name,"男生不让编辑哟!")
            '将新的错误行赋值给临时变量
            m_LastErrorRowData=tbl.Rows(e.Row).GetRowData()
            '禁止继续编辑数据
            e.Cancel=True
        End If
    End If
End Sub

 

 C#
// 定义一个临时变量,存储上一个设置了错误信息的行
private RowData m_LastErrorRowData = null;
public void StartEdit(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
    // 获得当前表
    SmGrid tbl = sender;
    // 如果当前是绑定行
    if (tbl.Rows(e.Row).DataIndex >= 0)
    {
        if (tbl.Rows(e.Row)["Gender"].CType<string>("") == "男")
        {
            // 如果之前有设置过错误信息,则在这里清空一下            
           if (m_LastErrorRowData != null) m_LastErrorRowData.ClearErrors();                
            // 设置新的错误信息提示
            tbl.Rows(e.Row).GetRowData().SetError(tbl.Cols(e.Col).Name, "男生不让编辑哟!");
            // 将新的错误行赋值给临时变量
            m_LastErrorRowData = tbl.Rows(e.Row).GetRowData();
            // 禁止继续编辑数据
            e.Cancel = true;
        }
    }
}