以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  设置插入行的复制单元格数据问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=118242)

--  作者:douglas738888
--  发布时间:2018/4/27 14:27:00
--  设置插入行的复制单元格数据问题

请教老师,下面代码,存在的问题是:不能把最后一行单元格的数据复制到插入新增的第一行的单元格中

 

Dim t As Table = Tables("年报")
Dim nr As Row = t.InsertNew                    \'插入新增行
If Tables("年报").Position = 0  Then            \'如果第一行是新增行,也是第一行,表格中无其他行时
    nr("去年上报时间") = Nothing                  \'新增行单元格为空值
Else
    Dim cr As Row = t.rows(t.Position+1)     \'如果表中有其他行,定位到最后一行
    If cr IsNot Nothing Then                        \'如果最后一行存在
        nr("去年上报时间") = cr("本年上报时间") \'最后一行的cr 复制到第一行的nr
    End If
End If


--  作者:有点甜
--  发布时间:2018/4/27 14:36:00
--  
Dim t As Table = Tables("年报")
If Tables("年报").Position = 0  Then            \'如果第一行是新增行,也是第一行,表格中无其他行时
    Dim nr As Row = t.InsertNew                    \'插入新增行
    nr("去年上报时间") = Nothing                  \'新增行单元格为空值
Else
    Dim cr As Row = t.current
    Dim nr As Row = t.InsertNew                    \'插入新增行
    If cr IsNot Nothing Then                        \'如果最后一行存在
        nr("去年上报时间") = cr("本年上报时间") \'最后一行的cr 复制到第一行的nr
    End If
End If

--  作者:douglas738888
--  发布时间:2018/4/27 14:54:00
--  

老师,用你指导的代码进行测试,还是不能把最后一行单元格的数据复制到新增行里面


--  作者:有点甜
--  发布时间:2018/4/27 14:57:00
--  
Dim t As Table = Tables("年报")
If Tables("年报").Position = 0  Then            \'如果第一行是新增行,也是第一行,表格中无其他行时
    Dim nr As Row = t.InsertNew                    \'插入新增行
    nr("去年上报时间") = Nothing                  \'新增行单元格为空值
Else
    Dim cr As Row = t.Rows(t.rows.Count-1)
    Dim nr As Row = t.InsertNew                    \'插入新增行
    If cr IsNot Nothing Then                        \'如果最后一行存在
        nr("去年上报时间") = cr("本年上报时间") \'最后一行的cr 复制到第一行的nr
    End If
End If

--  作者:douglas738888
--  发布时间:2018/4/27 15:17:00
--  

老师,还是不行,做了个例子请您看看  在窗口1操作

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:插入复制测试.foxdb

[此贴子已经被作者于2018/4/27 15:18:02编辑过]

--  作者:有点甜
--  发布时间:2018/4/27 15:37:00
--  
Dim t As Table = e.Form.controls("Table1").Table
If t.Rows.count = 0 Then
    Dim nr As Row = t.InsertNew                    \'插入新增行
    nr("去年上报时间") = Nothing                  \'新增行单元格为空值
Else
    Dim cr As Row = t.Current
    Dim nr As Row = t.InsertNew                    \'插入新增行
    If cr IsNot Nothing Then                        \'如果最后一行存在
        nr("去年上报时间") = cr("本年上报时间") \'最后一行的cr 复制到第一行的nr
    End If
End If