求编一道简单的vb题。(熟练使用list控件的进)

来源:百度知道 编辑:UC知道 时间:2024/09/28 09:38:34
1、新建一个工程,在窗体增加两个list(list1,list2).一个按钮。
2、工程运行时,list1的内容显示 a b c d e f g h i j 即:list1.list(0)~list1.list(9)分别为 a b c d e f g h i j
3、当点击按钮时,要求list1被选中的内容add到list2中。
4、当点击按钮时,若list2中已经存在list1选中得项。msgbox"exist"
真的很简单。但我编的总出错。大虾给正解。

楼上的你的代码运行不完全正确啊。我帮你改正了
Private Sub Command1_Click()
Dim i%, a$
For i = 0 To List2.ListCount - 1
If List2.List(i) = List1.List(List1.ListIndex) Then
a = MsgBox("exist")
Exit Sub
End If
Next i
List2.AddItem (List1.List(List1.ListIndex))
End Sub

Private Sub Form_Load()
List1.List(0) = "a"
List1.List(1) = "b"
List1.List(2) = "c"
List1.List(3) = "d"
List1.List(4) = "e"
List1.List(5) = "f"
List1.List(6) = "g"
List1.List(7) = "h"
List1.List(8) = "i"
List1.List(9) = "j"
List1.ListIndex = 0
End Sub

Private Sub Command1_Click()
Dim i%, a$
List2.AddItem (List1.List(List1.ListIndex))
For i = 0 To List2.ListCount - 2
If List2.List(i) =