|
-
Mar 29th, 2013, 05:41 PM
#1
Thread Starter
Fanatic Member
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.
-
Mar 29th, 2013, 06:27 PM
#2
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
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Mar 30th, 2013, 01:18 PM
#3
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|