此事件在控件进入编辑模式之前激发。它允许您通过将Cancel参数设置为true来防止编辑,或者重新设置BaseGrid.ComboList属性或重新设置BaseGrid.EditMask属性。
如果整列的选项或掩码相同,则可以使用BaseGrid.Cols("列名称").ComboList和BaseGrid.Cols("列名称").EditMask更有效地设置它们。在这种情况下,根本不需要处理StartEdit事件。
VB.Net |
|
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; } } } |