Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Team,

Need Your help in completing the below concept.

I have 2 listboxes with collections in it

Now what i require is,

until both list is empty, the first item of both listbox should be displayed in 3rd listbox.

For example.

list1 list2


123 778
234 909
355 344

it should look like

list3

123
778

only first index. ( onetime). this should get removed while adding the next set.

Thanks in advance.
Posted
Comments
Member 9989624 18-Apr-13 22:11pm    
i use this code. its working good for every click. how to loop this until both list is empty?

<pre lang="vb">
Dim selected As Object
Dim selected1 As Object
selected1 = ListBox2.Items(0).ToString
selected = ListBox1.Items(0).ToString
ListBox3.Items.Clear()
ListBox3.Items.Add(selected)
ListBox3.Items.Add(selected1)
ListBox2.Items.RemoveAt(0)
ListBox1.Items.RemoveAt(0)
</pre>

1 solution

As long as both listbox have the same number of items:

VB
Dim myList As New List(Of String)
Dim total As Integer = listbox1.Items.Count -1
For i As Integer = 0 To total
  myList.Add(listbox1.Items(i).ToString))
  myList.Add(listbox2.Items(i).ToString))
Next
For Each str As String In myList
  listbox3.Items.Add(str)
Next
listbox1.Items.Clear()
listbox2.Items.Clear()
 
Share this answer
 
v3
Comments
Member 9989624 18-Apr-13 22:29pm    
This code wrks good. Howerever what i need is only the first index of both listbox should be added in 3rd list. once the first index of listbox 1 and listbox 2 is added those should be removed.

This should happen till the first listbox is empty.

Please help
Idle_Force 18-Apr-13 22:34pm    
Updated!
Member 9989624 18-Apr-13 22:38pm    
Fantastic:) Thanks a lot.
Member 9989624 18-Apr-13 23:00pm    
i have posted another question please help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900