0
votes

I'm loading (let's say 300) IPs into listbox1, and what I'm looking to is to dividing all these IPs into three other listboxes. So that the first one of those listboxes gets 100 and the second listbox gets another 100 and the the third listbox gets the last 100.

ex. Listbox1 contains items A, B, C. Those items gets devided so that Listbox2 contains A, Listbox3 contains B, Listbox4 contains C.

1
Why don't you add these items to three different ListBoxes from the beginning? Have you determined the criteria that define these 3 groups? Is this your actual question? Have you tried something? - Jimi

1 Answers

0
votes

I divided the .Count of the listBox by 3 to find out how many entries go into each list box. I then created three loops to each handle their own listBox entries. I entered values in the listBox by the loop index, by selecting a value in listBox1 and then entering the selected value into listBox2.

There could be a more efficient way, but this is just one solution.

Dim numCount As Integer
numCount = listBox1.Items.Count
Dim perList As Integer = numCount / 3

For i As Integer = 0 To perList - 1
    listBox2.Items.Add(ListBox1.Items(i).ToString)
Next

For i As Integer = perList To perList * 2 - 1
    listBox3.Items.Add(ListBox1.Items(i).ToString)
Next

For i As Integer = perList * 2 To perList * 3 - 1
    listBox4.Items.Add(ListBox1.Items(i).ToString)
Next