以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何实现部分字段的上下行移动?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=68752)

--  作者:sxcspring
--  发布时间:2015/5/24 10:33:00
--  [求助]如何实现部分字段的上下行移动?

如图表列:卷号,订单,方案。卷号的行顺序不动,让“订单”和“方案”一起上下行移动(最好是可以多行的一起移),如何实现?

 

这个类似与ListView里面通过拖拽改变行的顺序,不同的是,我要表里面一部分字段的行顺序不变,另一部分改变。

 

如图,“卷号”与“订单“、“方案”的对应关系在在操作后全部改了。

 

请专家务必赐教。

 


图片点击可在新窗口打开查看此主题相关图片如下:111.jpg
图片点击可在新窗口打开查看

--  作者:大红袍
--  发布时间:2015/5/24 10:40:00
--  

参考代码,比如调换下一行的代码。

 

Dim cs() As String = {"第二列", "第三列"}

Dim cr As Row = Tables("表A").Current
If cr IsNot Nothing AndAlso cr.Index < Tables("表A").Rows.Count - 1 Then
    Dim nr As Row = Tables("表A").Rows(cr.Index + 1)
    For Each c As String In cs
        Dim temp As String = nr(c)
        nr(c) = cr(c)
        cr(c) = temp
    Next
End If


--  作者:sxcspring
--  发布时间:2015/5/24 11:05:00
--  

太谢谢了,不过能否再优化?

这个代码实现的是一行一行的移(就“方案”为AB的那个向上移3下),那如果是“方案”为A、B、C那3三行同时往下移一行呢?怎么弄?


图片点击可在新窗口打开查看此主题相关图片如下:222.jpg
图片点击可在新窗口打开查看

--  作者:大红袍
--  发布时间:2015/5/24 11:09:00
--  
Dim cs() As String = {"第二列", "第三列"}
Dim t As Table = Tables("表A")
If t.BottomPosition < t.Rows.Count - 1 Then
    For i As Integer = t.BottomPosition To t.TopPosition Step -1
        Dim cr As Row = t.Rows(i)
        Dim nr As Row = t.Rows(i + 1)
        For Each c As String In cs
            Dim temp As String = nr(c)
            nr(c) = cr(c)
            cr(c) = temp
        Next
    Next
End If