简体   繁体   English

vb.net如何从列表框中获取特定行并将其添加到其他列表框中

[英]vb.net How to get get specific lines from Listbox and add them to other Listboxes

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. 我正在加载(比方说300)IP到listbox1,我期待的是将所有这些IP分成三个其他列表框。 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. 因此,这些列表框中的第一个获得100,第二个列表框获得另外100个,第三个列表框获得最后100个。

ex. 恩。 Listbox1 contains items A, B, C. Those items gets devided so that Listbox2 contains A, Listbox3 contains B, Listbox4 contains C. Listbox1包含项目A,B,C。这些项目被分开,以便Listbox2包含A,Listbox3包含B,Listbox4包含C.

I divided the .Count of the listBox by 3 to find out how many entries go into each list box. 我将listBox的.Count除以3,以找出每个列表框中有多少条目。 I then created three loops to each handle their own listBox entries. 然后我创建了三个循环,每个循环处理自己的listBox条目。 I entered values in the listBox by the loop index, by selecting a value in listBox1 and then entering the selected value into listBox2. 我通过循环索引在listBox中输入值,方法是选择listBox1中的值,然后将所选值输入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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM