以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 请教ValidateEdit 事件 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=145067) |
-- 作者:hbhb -- 发布时间:2020/1/7 12:50:00 -- 请教ValidateEdit 事件 大师:我在表的ValidateEdit事件中写入如下代码,验证输入的内容,如果输入的有重复,禁止退出,同时希望输入的单元格的值恢复到原来的值,为何不行? 红色部分的设置无效,怎么解决? If e.Row.Index = 1 Then Dim lzf As String lzf = e.Row(e.Col.Name) \'-------重复值检测--------------------- Dim count As Integer = 0 For Each cl As Col In e.Table.Cols If cl.name <> e.Col.Name Then If e.Row(cl.Name) = e.Text And e.text <> "" Then count += 1 Exit For End If End If Next If count >= 1 Then MessageBox.Show("标题列不能重复!确认此列标题前,请删除其他列的相同标题","提示",MessageBoxButtons.OK,MessageBoxIcon.Information) e.Text = lzf e.cancel = True End If end if |
-- 作者:有点蓝 -- 发布时间:2020/1/7 14:16:00 -- e.Text = lzf e.cancel = True 上面2个有冲突,只能保留一个,e.cancel = True会使的单元格处于编辑状态,这时赋值是没有用的 或者改到datacolchanging事件 If Tables(e.DataTable.name).FindRow(e.DataRow) = 1 Then \'-------重复值检测--------------------- For Each cl As DataCol In e.DataTable.DataCols If cl.name <> e.DataCol.Name Then If e.DataRow(cl.Name) = e.NewValue And e.NewValue > "" Then MessageBox.Show("标题列不能重复!确认此列标题前,请删除其他列的相同标题","提示",MessageBoxButtons.OK,MessageBoxIcon.Information) e.cancel = True Tables(e.DataTable.name).Select(Tables(e.DataTable.name).RowSel,Tables(e.DataTable.name).ColSel-1) Return End If End If Next End If |
-- 作者:hbhb -- 发布时间:2020/1/7 14:35:00 -- 谢谢!这种功能,一般用哪一种方式处理(哪个事件)? |
-- 作者:有点蓝 -- 发布时间:2020/1/7 14:45:00 -- 写代码测试,哪个能用就用哪个 |