Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 18-Apr-13 16:40pm
Comments
Member 9989624 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

As long as both listbox have the same number of items:
 
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()
  Permalink  
v3
Comments
Member 9989624 at 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 at 18-Apr-13 22:34pm
   
Updated!
Member 9989624 at 18-Apr-13 22:38pm
   
Fantastic:) Thanks a lot.
Member 9989624 at 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)

  Print Answers RSS
0 Maciej Los 205
1 Richard MacCutchan 185
2 DamithSL 170
3 Tomas Takac 146
4 OriginalGriff 132
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100