avadhutd2
11-13-2009, 05:21 AM
I am transferring items from ListBox2 to ListBox1. These list boxes are having 2 columns. Hence have to transfer them taking this in care.
For a scenario when I have all the items in ListBox2 & select one by one item transfer from ListBox2 for transfer –
Here I can successfully transfer selected item to ListBox1 & that is the first item of ListBox1 (since ListBox1 is empty). After transfer ListBox1 contains 1 item.
When I attempt another item to transfer from ListBox2 to ListBox1, the earlier item is getting overwritten, by the newly transferred item.
What can be the problem here?
Thanks!
With ListBox2
For e = .ListCount - 1 To 0 Step -1
If .Selected(e) = True Then ' if selected then
If .List(e) = "DEMO_NAME" Then ' This code is for a member which is considered fixed in ListBox2
MsgBox "Cannot transfer ListItem DEMO_NAME from ListBox2 to ListBox1."
Else
If ListBox1.ListCount = 0 Then
ListBox1.AddItem .List(e), ListBox1.ListCount
ListBox1.List(ListBox1.ListCount - 1, 0) = .List(e, 0)
ListBox1.List(ListBox1.ListCount - 1, 1) = .List(e, 1)
.RemoveItem e ' remove from ListBox2
Else
ListBox1.List(ListBox1.ListCount - 1, 0) = .List(e, 0) '.Column(ListBox2.ListCount - 1, 1) = .List(e, 1)
ListBox1.List(ListBox1.ListCount - 1, 1) = .List(e, 1)
.RemoveItem e ' remove from ListBox2
End If
End If
End If
Next
End With
For a scenario when I have all the items in ListBox2 & select one by one item transfer from ListBox2 for transfer –
Here I can successfully transfer selected item to ListBox1 & that is the first item of ListBox1 (since ListBox1 is empty). After transfer ListBox1 contains 1 item.
When I attempt another item to transfer from ListBox2 to ListBox1, the earlier item is getting overwritten, by the newly transferred item.
What can be the problem here?
Thanks!
With ListBox2
For e = .ListCount - 1 To 0 Step -1
If .Selected(e) = True Then ' if selected then
If .List(e) = "DEMO_NAME" Then ' This code is for a member which is considered fixed in ListBox2
MsgBox "Cannot transfer ListItem DEMO_NAME from ListBox2 to ListBox1."
Else
If ListBox1.ListCount = 0 Then
ListBox1.AddItem .List(e), ListBox1.ListCount
ListBox1.List(ListBox1.ListCount - 1, 0) = .List(e, 0)
ListBox1.List(ListBox1.ListCount - 1, 1) = .List(e, 1)
.RemoveItem e ' remove from ListBox2
Else
ListBox1.List(ListBox1.ListCount - 1, 0) = .List(e, 0) '.Column(ListBox2.ListCount - 1, 1) = .List(e, 1)
ListBox1.List(ListBox1.ListCount - 1, 1) = .List(e, 1)
.RemoveItem e ' remove from ListBox2
End If
End If
End If
Next
End With