以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 精简代码(自动复制多行) (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=71185) |
-- 作者:一笑 -- 发布时间:2015/7/6 21:13:00 -- 精简代码(自动复制多行) 假定表A有个逻辑列,希望在某行选中此逻辑列时,自动将此行复制到表(事件汇总)。 表A的“轻度”为整数列,在表A的DataColChanged事件代码设置为: If e.DataCol.Name = "选择" Then Dim dr As DataRow = e.DataRow If dr("选择") = True And dr("轻度") > 0 Then Dim dt As DataTable = DataTables("事件汇总") Dim ndr As DataRow Dim n As Integer = dr("轻度") ndr = dt.AddNew(n) For Each dr1 As DataRow In dt.DataRows If dr1.RowState = DataRowState.Added Then dr1("译码日期") = dr("译码日期") dr1("性质") = "轻度" End If Next End If End If 表A另有“严重”列也为整数列,想重复以上操作,该如何精简地写代码?谢谢 |
-- 作者:大红袍 -- 发布时间:2015/7/6 21:21:00 -- If e.DataCol.Name = "选择" Then Dim dr As DataRow = e.DataRow Dim cs() As String = {"轻度","严重"} If dr("选择") = True Dim dt As DataTable = DataTables("事件汇总") Dim ndr As DataRow For Each c As String In cs Dim n As Integer = dr(c) If n > 0 Then ndr = dt.AddNew(n) For Each dr1 As DataRow In dt.DataRows If dr1.RowState = DataRowState.Added Then dr1("译码日期") = dr("译码日期") dr1("性质") = "轻度" dr1.Save End If Next End If Next End If End If |