Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
自动复制行
假定表A有个逻辑列,希望在某行选中此逻辑列时,自动将此行复制到表B。
为此可以将表A的DataColChanged事件代码设置为:
If e.DataCol.Name =
"逻辑列名"
AndAlso e.DataRow("逻辑列名")
= True
Then
Dim
dr As
DataRow = DataTables("表B").AddNew
For
Each dc As
DataCol
In
DataTables("表B").DataCols
dr(dc.Name) = e.DataRow(dc.Name)
Next
End
If
上面的代码假定表A和表B的结构相同,且列名相同。
如果列名不同,或者只需复制部分列,可以参考下面的代码:
If e.DataCol.Name =
"逻辑列名"
AndAlso e.DataRow("逻辑列名")
= True
Then
Dim
nma() As
String = {"A1","A2","A3","A4"} 'A表数据来源列
Dim
nmb()
As
String = {"B1","B2","B3","B4"}
'B表数据接收列
Dim
dr
As
DataRow =
DataTables("表B").AddNew
For
i As
Integer = 0
To nma.Length - 1
dr(nmb(i)) = e.DataRow(nma(i))
Next
End
If
如果"逻辑列名"选择以后A表自动复制数据到B表,如果撒消选择后把复制的数据删除,那么以上的公式如何修改?
楼主:需要在表B 中加入一列"id"
If e.DataCol.Name = "逻辑列名" Then
If e.DataRow("逻辑列名") = True Then
Dim dr As DataRow = DataTables("表B").AddNew
For Each dc As DataCol In DataTables("表B").DataCols
If dc.name ="id" Then
dr("id") =e.DataRow("_identify")
Else
dr(dc.Name) = e.DataRow(dc.Name)
End If
Next
Else
Dim tr As DataRow =DataTables("表B").find("id ="& e.DataRow("_identify"))
If tr IsNot Nothing Then
tr.delete()
End If
End If
End If
判断逻辑列= false 后
dr(dc.Name) = e.DataRow(dc.Name) 改为:dr(dc.Name) = nothing
4楼表A窗口应是你所要
Datatables("表B").Deletefor("列名='" & 表A相对应的条件 & "'") 以上的公式能帮我在4楼的文件表A公式里插入,改成我要的效果吗? |
设置表A的DataRowDeleting事件为:
Dim dr As DataRow = DataTables("表B").Find("ID = " & e.DataRow("_Identify"))
If dr IsNot Nothing Then
dr.Delete
End If
dr = DataTables("表C").Find("ID = " & e.DataRow("_Identify"))
If dr IsNot Nothing Then
dr.Delete
End If
这样在表A删除行,会自动删除表B和表C对应的行。