怎么做这道VB题? 5
在名称为Form1的窗体上放置两个列表框,名称分别为list1和list2.在list1中添加"第一题","第二题"...'第八题',并设置Multiselect属性为2...
在名称为Form1的窗体上放置两个列表框,名称分别为list1和list2.在list1中添加"第一题","第二题"...'第八题',并设置Multiselect属性为2(要求在控件属性中设置实现).再放置一个名称为Cmd1,标题为"复制"的命令按钮.程序运行后,如果单击"复制"按钮,将List1中选中的内容(至少两项)复制到list2中.如果选择的项数少于2项,用消息框提示"请选择至少两项". 这道题的代码是什么?
展开
展开全部
Multiselect属性为2(要求在控件属性中设置实现)不能在代码实现。如果要“第一题”“第二题”加可能要自己一个个加。
Private Sub Form_Load()
For i = 1 To 8
List1.AddItem "第" & i & "题"
Next i
Cmd1.Caption = "复制"
End Sub
Private Sub Cmd1_Click()
If List1.SelCount >= 2 Then
For i = 0 To 7
If List1.Selected(i) = True Then List2.AddItem (List1.List(i))
Next i
Else
MsgBox "请选择至少两项"
End If
End Sub
Private Sub Form_Load()
For i = 1 To 8
List1.AddItem "第" & i & "题"
Next i
Cmd1.Caption = "复制"
End Sub
Private Sub Cmd1_Click()
If List1.SelCount >= 2 Then
For i = 0 To 7
If List1.Selected(i) = True Then List2.AddItem (List1.List(i))
Next i
Else
MsgBox "请选择至少两项"
End If
End Sub
展开全部
方法比较笨,不知道是不是还有更简单的
Private Sub Cmd1_Click()
Dim Count As Integer
Count = 0
For i = 0 To List1.ListCount - 1
If (List1.ItemData(i) = 1) Then
Count = Count + 1
End If
Next i
If Count < 2 Then
MsgBox "请选择至少两项"
Exit Sub
End If
List2.Clear
For i = 0 To List1.ListCount - 1
If (List1.ItemData(i) = 1) Then
List2.AddItem (List1.List(i))
End If
Next i
End Sub
Private Sub List1_Click()
Dim index As Integer
i = List1.ListIndex
If (List1.ItemData(i) = 0) Then
List1.ItemData(i) = 1
Else
List1.ItemData(i) = 0
End If
End Sub
Private Sub Cmd1_Click()
Dim Count As Integer
Count = 0
For i = 0 To List1.ListCount - 1
If (List1.ItemData(i) = 1) Then
Count = Count + 1
End If
Next i
If Count < 2 Then
MsgBox "请选择至少两项"
Exit Sub
End If
List2.Clear
For i = 0 To List1.ListCount - 1
If (List1.ItemData(i) = 1) Then
List2.AddItem (List1.List(i))
End If
Next i
End Sub
Private Sub List1_Click()
Dim index As Integer
i = List1.ListIndex
If (List1.ItemData(i) = 0) Then
List1.ItemData(i) = 1
Else
List1.ItemData(i) = 0
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询