Distributing items across several listboxes.
Hey guys, long time since I posted here. I've been working in C#, and have yet to find a decent *ACTIVE* C# forum for help...
So, heres my scenario:
ListboxQueue 1: 80 Items. (Queue)
ListboxWork 1(through 6): 0 Items (Work 2 be done)
ListBoxWork is actually sitting inside of a List(of Listbox).
What is the best way to distribute each item from the queue into the work (with a max of 8 per LB)...
Now, I could do a lot of if statements, but I would like it to use the List(of listbox) to do the spread...
Now, I have 80 items, 6 "workers"...with a max of 8 per worker, it'd come out to 48...which means i'd like to leave the last 32 items in the queue.
(I know I stated this is for C#, but I also know how to convert VB as well)
Thanks for the solution.
I am not necessarily looking for a code snippet, but more so a direction.
Re: Distributing items across several listboxes.
For i = 0 To 41 Step 6:For j = 0 to 5: From LBQ i+J to Listbox i
Re: Distributing items across several listboxes.
try this:
Code:
Public Class Form1
Dim listBoxes() As ListBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
listBoxes = New ListBox() {ListboxWork1, ListboxWork2, ListboxWork3, ListboxWork4, ListboxWork5, ListboxWork6}
ListboxQueue.Items.AddRange(Enumerable.Range(1, 80).Select(Function(x) x.ToString).ToArray)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim items() As String = ListboxQueue.Items.Cast(Of String).ToArray
For x As Integer = 0 To 5
listBoxes(x).Items.AddRange(items.Skip(x * 8).Take(8).ToArray)
For x2 As Integer = 0 To 7
ListboxQueue.Items.RemoveAt(0)
Next
Next
End Sub
End Class