Re: [RESOLVED] List to List
If you have any code that might repeat the AddItem method you may want to add the Clear method as I did here. Without this line repeated clicks would cause List2 to not match List1. Since you have your code in your Form_Load event, it won't matter though. ;)
Code:
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
'** insure that List2 always matches List1 by first clearing List2. **
If Form2.List2.ListCount <> 0 Then Form2.List2.Clear
For i = 0 To Form1.List1.ListCount - 1
Form1.List1.ListIndex = i
Form2.List2.AddItem (Form1.List1.List(Form1.List1.ListIndex))
Next i
End Sub
Re: [RESOLVED] List to List
Code:
Public Function MoveFromListToList(ByVal Index As Integer, ByRef FromList As Control, ByRef ToList As Control) As Long
On Error GoTo errHandler
' Removes a selected item from one list and puts it in another list.
' Returns 0 if succesful or -1 if nothing moved.
MoveFromListToList = -1
If Index < 0 Then Exit Function ' Return -1
If Not IsList(FromList) Then Exit Function ' Return -1
If Not IsList(ToList) Then Exit Function ' Return -1
With ToList
.AddItem FromList.List(Index)
.ItemData(.NewIndex) = FromList.ItemData(Index)
End With
FromList.RemoveItem Index
' Return 0
MoveFromListToList = 0
Exit Function
errHandler:
MoveFromListToList = -1
End Function
Public Function IsList(List As Control) As Boolean
' Determines if control is a list.
IsList = (TypeName(List) = "ListBox") Or (TypeName(List) = "ComboBox") Or (TypeName(List) = "FileListBox")
End Function