How to choose with List in VB

Source: Internet
Author: User
Tags exit comments empty integer
Provide
Single Item function:
Cmddel_click
Cmdadd_click
Multiple Item Function:
Cmddelall_click
Cmdaddall_click
--------------------------------------------------------------------------------------------------------------- ------
' Option Explicit

' Author:nyb
' Time:2002-04-05
' Incoming list1,list2, and then we can handle the item in List1, and List2.
' *all areas of code where modifications are necessary
' *to integrate this object with a project are documented
' With comments denoted by:.
' *to locate these comments,search for ' *note::.
'****************************************************************************************

Public Sub Cmddelall_click (List1 as ListBox, List2 as ListBox) ' <<
' *purpose:delete all List2.item
' *accept:list1 no use, List2 processing object
For i = (list2.listcount-1) to 0 Step-1
List2.removeitem I
Next I
End Sub
Public Sub Cmdadd2to1_click (List1 as ListBox, List2 as ListBox, List3 as ListBox) ' >>
' *purpose:all item of List1 and List2 are inputed to List3
' *accept:list1,list2
For i = 0 to (list1.listcount-1)
List3.additem List1.list (i)
Next I
For i = 0 to (list2.listcount-1)
List3.additem List2.list (i)
Next I
End Sub

Public Sub Cmdaddall_click (List1 as ListBox, List2 as ListBox, Index as Integer) ' >>
' *purpose:add all item of List1 inputed to List2.if item had been there, It won ' t be inputed
' *accept:list1,list2
If list2.listcount = 0 Then
For i = 0 to (list1.listcount-1)
List2.additem List1.list (i)
Next I
Else
For i = 0 to (list1.listcount-1)
Flag = checkselected (List1, List2, List1.list (i))
If Flag = "Notbe" Then list2.additem list1.list (i)
Next I
End If
End Sub


Public Sub Cmddel_click (List1 as ListBox, List2 as ListBox) ' <---
' *purpose:the selected items of List2 are cleared
' *accept:list1 no use, List2 processing object
Dim I as Integer
If list2.selcount > 0 Then
For i = (list2.listcount-1) to 0 Step-1
If list2.selected (i) = True Then List2.removeitem i
Next I
End If
End Sub

Public Sub Cmdadd_click (List1 as ListBox, List2 as ListBox, Index as Integer) '--->
' *purpose:the selected items of List1 is inputed into List2
' List2 is empty, List2 can be selected more, then items selected in List1 are inputed to List2
' List2 is not empty, list2 can choose more, then check whether the item is in List2, if in, then don't add into List2
' List2 is set to a single selection, then List2 only add the first selected item in List1
' *accept:list1 selected items, List2 for the listbox to join
Dim I as Integer
Dim Flag as String

If Index > 0 Then
If list2.listcount >= 1 Then
If Index = 2 Then
If List2.listcount >= 2 Then
If list1.multiselect = 0 Then
MsgBox "can only select two phase contrast!" ", vbexclamation," Operation Tips! "
Exit Sub
End If
End If
End If
End If
End If

If list2.listcount = 0 and list2.multiselect = 2 Then
For i = 0 to (list1.listcount-1)
If list1.selected (i) = True Then list2.additem list1.list (i)
Next I
ElseIf list2.listcount > 0 and list2.multiselect = 2 Then
For i = 0 to (list1.listcount-1)
Flag = checkselected (List1, List2, List1.list (i))
If list1.selected (i) = True and Flag = "notbe" Then list2.additem list1.list (i)
Next I
ElseIf list2.multiselect = 0 Then
Call Cmddelall_click (List1, List2)
For i = 0 to (list1.listcount-1)
If list1.selected (i) = True Then list2.additem list1.list (i)
Next I
End If
Call Clearselect (LIST1)
End Sub

Private Function checkselected (List1 as ListBox, List2 as ListBox, Cityitem as String) as String
' *purpose: ' Check if item has been added, add checkselected = ' be '
' *accept:list1 selected items, List2 for the Listbox,cityitem to be added as a selected item in List1
' *feedback:checkselected, ' be ' indicates that this item exists in the List2
For i = (list2.listcount-1) to 0 Step-1
If Cityitem = list2.list (i) Then
checkselected = "Be"
Exit for
else:checkselected = "Notbe"
End If
Next I
End Function

Private Sub Clearselect (List1)
' *purpose:clear List1 ' s selected
' *accept:list1, the list box to clear selected
For i = 0 to List1.listcount-1
If list1.selected (i) = True Then
list1.selected (i) = False
End If
Next I
End Sub






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.