以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [请教] 两个listbox控件,互相比较,排除重复值出错  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=56804)

--  作者:bahamute
--  发布时间:2014/9/12 16:15:00
--  [请教] 两个listbox控件,互相比较,排除重复值出错
请教,一下代码那里有问题,
运行报错InvalidArgument=“83”的值对于“index”无效。
参数名: index

Dim lst1 As WinForm.ListBox= e.Form.Controls("ListBox1")
Dim lst2 As WinForm.ListBox= e.Form.Controls("ListBox2")

If lst2.Items.Count>0 Then                                \'判断控件2是否有值
    For m As Integer = 0 To lst2.Items.Count - 1        
        For i As Integer = 0 To lst1.Items.Count - 1
            If lst2.Items(m) = lst1.Items(i) Then        \'如果有重复值
                lst1.Items.Remove(lst1.Items(i))           \'则从lst1控件中移除。
            End If
        Next
    Next
End If

--  作者:Bin
--  发布时间:2014/9/12 16:21:00
--  
for each s as string in lst2.items
    if lst1.items.Contains(s) then
      lst1.items.remove(s)
    end if
next

--  作者:bahamute
--  发布时间:2014/9/12 16:23:00
--  
果然高手,谢谢。