Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Does anyone know how to split items in listbox / 5?

Automatically, this items / 5 and split to 5 other listboxes.

For example, we have 1000 items in Listbox 1.
I want to split these 1000 items to the 5 different listboxes.
What code should I use here?

P.S.: Listbox 1 should have 200 items, also listbox 2, 3, 4 and 5.

What I have tried:

..................................................
Posted
Updated 3-Apr-22 9:53am
v3
Comments
Richard MacCutchan 3-Apr-22 8:59am    
Use a loop that selects each 5 items and adds them to the new listboxes.
Ashkan X 3-Apr-22 12:24pm    
how can i move only five first item ? without click on them
Richard MacCutchan 4-Apr-22 5:00am    
OriginalGriff 3-Apr-22 9:53am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?

That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!

Use the "Improve question" widget to edit your question and provide better information.
Ashkan X 3-Apr-22 14:44pm    
Thanks for your help
i edited what i meant now can you suggest anything?

1 solution

Think of it.
Imagine, you need only one loop. Based on your example - listbox1 has got 1000 items. Then you want to split it into 5 listboxes.

C#
int j = 0;
for(int i=0; i<1000; i++)
{
	j = i % 5;
	Console.WriteLine($"Item {i} goes to the listbox {j}");
}

Result:
tet
Item 0 goes to the listbox 0
Item 1 goes to the listbox 1
Item 2 goes to the listbox 2
Item 3 goes to the listbox 3
Item 4 goes to the listbox 4
Item 5 goes to the listbox 0
Item 6 goes to the listbox 1
Item 7 goes to the listbox 2
Item 8 goes to the listbox 3
Item 9 goes to the listbox 4
Item 10 goes to the listbox 0
Item 11 goes to the listbox 1
...
Item 994 goes to the listbox 4
Item 995 goes to the listbox 0
Item 996 goes to the listbox 1
Item 997 goes to the listbox 2
Item 998 goes to the listbox 3
Item 999 goes to the listbox 4


You can also split items different way. 200 first items can go into listbox #1, next 200 items can go into listbox #2, etc. You need to modify above code to your needs.

Good luck!
 
Share this answer
 
v2
Comments
Ashkan X 3-Apr-22 15:04pm    
Thanks for your but it didn't help
i understand the loop but i don't know how can i move the items to another listbox without selecting it with mouse i want it automaticly do it
Maciej Los 3-Apr-22 15:10pm    
Does above example uses user interaction? No!

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