以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]关于LISTVIEW的遍历问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=91245)

--  作者:沦落深蓝
--  发布时间:2016/10/5 10:33:00
--  [求助]关于LISTVIEW的遍历问题

请问老师,对于一个窗口内的多个listview,以列表显示后,想要实现双击互动,用for each遍历可行吗,为什么只有第一个listview相应了

双击动作,所有listview数据都来自同一个表,如果遍历不行只能逐个编写了

 

 

这是模拟按钮程序

············

Dim lvws() As Winform.ListView = {lvw1,lvw2,lvw3,lvw4,lvw5,lvw6,lvw7}

For Each lvw As WinForm.ListView In lvws
    Dim vr As WinForm.ListViewRow = lvw.Current \'获取ListView的当前行
    If vr Is Nothing Then \'如果不存在当前行,也就是内有选定任何一行
        Return
    End If
    Dim dr As DataRow = vr.tag \'获取此行对应的DataRow
    Dim ps As Integer = Tables("主窗口").FindRow(dr)
    If ps >= 0 Then
        Tables("主窗口").Position = ps
        Forms("保养维护记录窗口").Open
        For Each cl As WinForm.ListViewColumn In lvw.Columns \'逐列更新值
            vr(cl.Name) = dr(cl.Name)
        Next
    End If
Next

 

 

这是其中一个listview3的程序

\'初驶保养判定程序
For Each dr As DataRow In DataTables("主窗口").Select("","机械分类")\'列出所有装备代号
    Dim y,m,d As Integer
    If dr.Isnull("初驶保养时间") =True And dr("装备状态") ="良好" Then
        If dr("工作时间")-dr("大修2") >=50 Then
            Dim vr As WinForm.ListViewRow = lvw3.Rows.Add()
            vr.Text = dr("装备代号")
            vr.Name = dr("装备代号") \'将ListViewRow的Name属性设置为装备代号
            vr.Font = New Font("微软雅黑",12)
            If dr("机械分类") = "蓄电池叉车" Then
                vr.ImageKey = "蓄电池叉车"
            Else If dr("机械分类") = "蓄电池牵引车" Then
                vr.ImageKey = "蓄电池牵引车"
            Else
                vr.ImageKey = "内燃机械"
            End If
            vr.Tag= dr \'将DataRow赋值给ListViewRow的Tag属性,将二者联系起来
        End If
    End If
Next

 

 

ListView的RowActivate事件代码设置为:

Dim
btn As WinForm.Button = e.Form.Controls("btnEdit")
btn
.PerformClick() \'模拟单击修改按钮


--  作者:狐狸爸爸
--  发布时间:2016/10/5 11:25:00
--  
Dim lvws() As Winform.ListView = {lvw1,lvw2,lvw3,lvw4,lvw5,lvw6,lvw7}
For Each lvw As WinForm.ListView In lvws
    Dim vr As WinForm.ListViewRow = lvw.Current \'获取ListView的当前行
    If vr Is Nothing Then \'如果不存在当前行,也就是内有选定任何一行
       Continue For
    End If
    Dim dr As DataRow = vr.tag \'获取此行对应的DataRow
    Dim ps As Integer = Tables("主窗口").FindRow(dr)
    If ps >= 0 Then
        Tables("主窗口").Position = ps
        Forms("保养维护记录窗口").Open
        For Each cl As WinForm.ListViewColumn In lvw.Columns \'逐列更新值
            vr(cl.Name) = dr(cl.Name)
        Next
    End If
Next

--  作者:沦落深蓝
--  发布时间:2016/10/6 22:28:00
--  
感谢老师的指导