Results 1 to 2 of 2

Thread: Array used in listboxes?

Threaded View

  1. #2
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    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.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .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
  •  



Click Here to Expand Forum to Full Width