Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi-Select Paired ListBoxes

Status
Not open for further replies.

bgv

Programmer
Sep 23, 2003
29
US
I have downloaded an example for paired listboxes from 2000.mdb. It works well for a single selection, but I want to implement it as a pair of multi-select listboxes. I have changed the listbox parameters as extended multi-select fields and have gotten it to work, though very in-elegantly as follows for removing elements from the list of available items as part of the cmdAdd_Click event, in lines 28-31:

1 Dim lstAvailable As Access.ListBox
2 Dim lstSelected As Access.ListBox
3 Dim strItem As String
4 Dim intItem As Integer
5 Dim varItem As Variant
6 Dim intIndex As Integer
7 Dim intCount As Integer
8 Dim intRow As Integer
9 Dim intColumn As Integer
10 Dim n, i As Integer
11
12 Private Sub cmdAdd_Click()
13
14 On Error GoTo ErrorHandler
15
16 Dim varList(2000) As Variant
17 Set lstSelected = Me![lstSelectedItemsSingle]
18 Set lstAvailable = Me![lstAvailableItemsSingle]
19
20 'Check that at least one item has been selected
21 Debug.Print "Item count: " & lstAvailable.ItemsSelected.Count
22 If lstAvailable.ItemsSelected.Count = 0 Then
23 MsgBox "Please select an item"
24 lstAvailable.SetFocus
25 Exit Sub
26 End If
27
28 n = 0
29 For Each varItem In lstAvailable.ItemsSelected
30 strItem = lstAvailable.ItemData(varItem)
31 varList(n) = varItem
32 'Add selected item to Selected Items list
33 lstSelected.AddItem Item:=strItem
34 n = n + 1
35 Next
36
37 For i = 0 To n Step 1
38 varItem = varList(n)
39 'Delete selected item from Available Items list
40 lstAvailable.RemoveItem Index:=varItem
41 Next
...
...
...

I would appreciate any help in making it more efficient. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top