自动复制行

假定表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


本页地址:http://www.foxtable.com/webhelp/topics/2292.htm