VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 将数据从一个列表框移入另一个列表框
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:9390, 日期:2001-06-04
将数据从一个列表框移入另一个列表框

关键词:Visual Basic

Here is another way to move data from one list box to another and back. The four buttons ( ADD, ADD ALL, REMOVE and REMOVE ALL) are a control array and the subroutine FourButtons handles all movements between the two list boxes. I tried to use the least amount of code. This app is an unattended bulk printing app.  

Private Sub FourButtons(ByVal Index As Integer)
Screen.MousePointer = 11
Select Case Index
    Case 0 注释: Add selected contractId from List1 to List2
        If List1.ListCount = 0 Then
            Screen.MousePointer = 0
            Exit Sub
        End If
        If List1.ListIndex = -1 Then    注释:nothing is selected
            List1.SetFocus
            List1.Selected(0) = True    注释:select the first item in the list.
        End If
        DoEvents
        List2.AddItem List1.Text
        List1.RemoveItem List1.ListIndex

    Case 1 注释: Add All ContractIds from List1 to List2
        If List1.ListCount = 0 Then
            Screen.MousePointer = 0
            Exit Sub
        End If
        If List1.ListIndex = -1 Then
            List1.SetFocus
            List1.Selected(0) = True
        End If
        DoEvents
        For i = (List1.ListCount - 1) To 0 Step -1
            List2.AddItem List1.List(i)
            DoEvents
        Next i
        List1.Clear

    Case 2 注释: Remove selected contractId from List2 to List1
        If List2.ListCount = 0 Then
            Screen.MousePointer = 0
            Exit Sub
        End If
        If List2.ListCount = 0 Then Exit Sub
        If List2.ListIndex = -1 Then
            List2.SetFocus
            List2.Selected(0) = True
        End If

        List1.AddItem List2.Text
        List2.RemoveItem List2.ListIndex

    Case 3 注释: Remove All ContractIds From List2 to List1
        If List2.ListCount = 0 Then
            Screen.MousePointer = 0
            Exit Sub
        End If
        If List2.ListCount = 0 Then Exit Sub
        If List2.ListIndex = -1 Then  注释:nothing is selected.
            List2.SetFocus            注释:set focus.
            List2.Selected(0) = True  注释:select first item in list.
        End If
        For i = (List2.ListCount - 1) To 0 Step -1
            List1.AddItem List2.List(i)
            DoEvents
        Next i
        List2.Clear

End Select
Screen.MousePointer = 0
End Sub