Results 1 to 2 of 2

Thread: Array used in listboxes?

  1. #1
    New Member
    Join Date
    Sep 12
    Posts
    1

    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.

  2. #2
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 11
    Posts
    585

    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:
    1. listBox1.Items.AddRange("ABCDEFG".Select(c => c.ToString()).ToArray());
    2. 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:
    1. string s = "ABCDEFG";
    2. string nums = "123";
    3.  
    4. var x1 = (from char c in s
    5.           from char n in nums
    6.           select string.Format("{0}{1}", c, n)).ToArray();
    7.  
    8. var x2 = (from char c in s
    9.           from char n in nums
    10.           select string.Format("{0}{1}", n, c)).ToArray();
    11.  
    12. listBox1.Items.AddRange(x1);
    13. listBox2.Items.AddRange(x2);
    Last edited by AceInfinity; Sep 23rd, 2012 at 01:19 AM.
    <<<------------
    < Please rate my post if this helped you out. Any kind of thanks is gladly appreciated >



    VB Programming (2012 - Present)
    ®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
  •