首页 热点资讯 义务教育 高等教育 出国留学 考研考公
您的当前位置:首页正文

VBLISTBOX属性

2021-02-08 来源:华拓网
VBLISTBOX属性

additem 添加属性listcount总记录数listindex索引值

Private Sub Form_Load()List1.AddItem \"⼴东省⼴州市\"List1.AddItem \"⼴东省河源市\"List1.AddItem \"⼴东省惠州市\"List1.ListIndex = 0End Sub

Private Sub LeftAll_Click()Dim i As Integer

For i = 0 To List2.ListCount - 1 List1.AddItem List2.List(i) Next

List2.Clear

List1.ListIndex = List1.NewIndex

End Sub

Private Sub LeftOne_Click()Dim i As Integer

If List2.ListCount = 0 Then Exit Sub List1.AddItem List2.Text i = List2.ListIndex List2.RemoveItem i

List1.ListIndex = List1.NewIndex If List2.ListCount > 0 Then If i > List2.ListCount - 1 Then List2.ListIndex = i - 1 Else

List2.ListIndex = i End If End IfEnd Sub

Private Sub List1_dblclick()RightOne_ClickEnd Sub

Private Sub List2_dblClick()LeftOne_ClickEnd Sub

Private Sub RightOne_Click()Dim i As Integer

If List1.ListCount = 0 Then Exit Sub List2.AddItem List1.Text i = List1.ListIndex

List1.RemoveItem List1.ListIndex If List1.ListCount > 0 Then If i > List1.ListCount - 1 Then List1.ListIndex = i - 1 Else

List1.ListIndex = i End IfEnd If

List2.ListIndex = List2.NewIndexEnd Sub

Private Sub RightALL_Click()Dim i As Integer

For i = 0 To List1.ListCount - 1List2.AddItem List1.List(i)

Next

List1.Clear

List2.ListIndex = 0End Sub

Private Sub Up_Click()Dim Up As IntegerWith List2

If .ListIndex < 0 Then Exit Sub Up = .ListIndex

If Up = 0 Then Exit Sub '不能将第⼀个项⽬向上移动 .AddItem .Text, Up - 1 '向上移动项⽬ .RemoveItem Up + 1 '删除旧的项⽬

.Selected(Up - 1) = True '选择刚刚被移动的项⽬ End WithEnd Sub

Private Sub Down_Click()Dim Down As Integer With List2

If .ListIndex < 0 Then Exit Sub Down = .ListIndex

If Down = .ListCount - 1 Then Exit Sub '不能将最后的项⽬向下移动 .AddItem .Text, Down + 2 '向下移动项⽬ .RemoveItem Down '删除旧的项⽬

.Selected(Down + 1) = True '选择刚刚被移动的项⽬

End With

End Sub附有截图

先新建两个listbox⼀个命名为:list1和⼀个list2

和六个命令按钮,详细命名见上图即可。为左、右、全左、全右、上、下

因篇幅问题不能全部显示,请点此查看更多更全内容