以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 自动复制行 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=162273) |
-- 作者:a272797388 -- 发布时间:2021/4/11 23:10:00 -- 自动复制行 假定表A有个逻辑列,希望在某行选中此逻辑列时,自动将此行复制到表B。 为此可以将表A的DataColChanged事件代码设置为: If e.DataCol.Name =
"逻辑列名"
AndAlso e.DataRow("逻辑列名")
= True
Then 上面的代码假定表A和表B的结构相同,且列名相同。 如果列名不同,或者只需复制部分列,可以参考下面的代码: If e.DataCol.Name =
"逻辑列名"
AndAlso e.DataRow("逻辑列名")
= True
Then 请问以上的命令, 我能不能再加一个限制,如果表A中性别列为“男”在表B中自动复制行,如果表A中性别列为“女”,在表C中自动复制行,如果表A中性别为“人妖”的在表D中自动复制行。 请问专家, 如何能实现? |
-- 作者:有点蓝 -- 发布时间:2021/4/12 8:35:00 -- If e.DataCol.Name = "性别" Dim s As String Select Case e.DataRow("性别") Case "男" s = "表B" Case "女" s = "表C" Case "人妖" s = "表D" Case Else Return End Select Dim dr As DataRow = DataTables(s).AddNew For Each dc As DataCol In DataTables(s).DataCols dr(dc.Name) = e.DataRow(dc.Name) Next End If
|
-- 作者:a272797388 -- 发布时间:2021/4/12 22:04:00 -- 请问这段代码如何修改? If e.DataCol.Name = "性别" Dim s As String Select Case e.DataRow("性别") Case "男" s = "表B" Case "女" s = "表C" Case "人妖" s = "表D" Case Else Return End Select If e.DataCol.Name = "逻辑列名" AndAlso e.DataRow("逻辑列名") = True Then Dim nma() As String = {"第一列","第二列","第三列","第四列"} \'A表数据来源列 Dim nmb() As String = {"第一列","第二列","第三列","第四列"} \'B表数据接收列 Dim dr As DataRow = DataTables(s).AddNew For i As Integer = 0 To nma.Length - 1 dr(nmb(i)) = e.DataRow(nma(i)) Next End If End If |
-- 作者:有点蓝 -- 发布时间:2021/4/12 22:33:00 -- If e.DataCol.Name = "性别" orelse e.DataCol.Name = "逻辑列名" If e.DataRow("逻辑列名") = True Then
Dim s As String Select Case e.DataRow("性别") Case "男" s = "表B" Case "女" s = "表C" Case "人妖" s = "表D" Case Else Return End Select Dim nma() As String = {"第一列","第二列","第三列","第四列"} \'A表数据来源列 Dim nmb() As String = {"第一列","第二列","第三列","第四列"} \'B表数据接收列 Dim dr As DataRow = DataTables(s).AddNew For i As Integer = 0 To nma.Length - 1 dr(nmb(i)) = e.DataRow(nma(i)) Next End If End If |