|
-
Sep 20th, 2012, 05:53 AM
#1
Thread Starter
New Member
Array used in listboxes?
Hey, I have an array with 5 rows 3 columns, and it goes like A B C D E, 1 2 3.
I need to add the A B C D E into one list box and the 1 2 3 into another.
I have programmed this but it only shows 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4
(Did not include non important parts)
for (int row = 0; row <= stringArray.GetUpperBound(0); row++)
{
for (int seat = 0; seat <= stringArray.GetUpperBound(1); seat++)
{
if (string.IsNullOrEmpty(stringArray[row, seat]))
{
Seat theSeat = new Seat();
theSeat.text = row.ToString();
theSeat.row = row;
theSeat.seat = seat;
if (flag)
{
int itemIndex = listBoxLetters.Items.Add(theSeat);
}
Help would be appreciated! thanks.
-
Sep 23rd, 2012, 01:10 AM
#2
Re: Array used in listboxes?
What do you mean "an array with 5 rows 3 columns"? An array is not a DataTable, although to visualize multi-dimensional arrays, it may be easier to picture it that way. I don't get what you're trying to do. Why don't you just do this if you want to add "A" to "E" in one ListBox and "1" to "3" in the other:
csharp Code:
listBox1.Items.AddRange("ABCDEFG".Select(c => c.ToString()).ToArray());
listBox2.Items.AddRange(Enumerable.Range(1, 3).Select(i => i.ToString()).ToArray());
If you're meaning to add "A1", "A2", "A3", "B1", "B2", etc... to one Listbox, and "1A", "2A", 3A", ect... to the other Listbox. Then:
csharp Code:
string s = "ABCDEFG";
string nums = "123";
var x1 = (from char c in s
from char n in nums
select string.Format("{0}{1}", c, n)).ToArray();
var x2 = (from char c in s
from char n in nums
select string.Format("{0}{1}", n, c)).ToArray();
listBox1.Items.AddRange(x1);
listBox2.Items.AddRange(x2);
Last edited by AceInfinity; Sep 23rd, 2012 at 01:19 AM.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
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
|