Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Displaying Multidimensional Arrays in a Form

Displaying Multidimensional Arrays in a Form

Scheduled Pinned Locked Moved C#
questiondata-structureshelp
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    crushinghellhammer
    wrote on last edited by
    #1

    I have what should be a simple problem, but I'm not able to figure it out. Suppose I have a 5 by 10 array. I populate the array, and now want to display this on a form. The array is populated in a separate codefile, which passes the array to the main form file. When I click on a button, I want to be able to see each row of the array i.e if the array is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 etc etc... Clicking the button once should give me 1 2 3 4 5 6 7 8 9 10 Clicking again should give me 11 ... 20 and so on. How do I make this happen? I have a label named "labDisp" and a button "btnShow" on the form. Thank you.

    C C 2 Replies Last reply
    0
    • C crushinghellhammer

      I have what should be a simple problem, but I'm not able to figure it out. Suppose I have a 5 by 10 array. I populate the array, and now want to display this on a form. The array is populated in a separate codefile, which passes the array to the main form file. When I click on a button, I want to be able to see each row of the array i.e if the array is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 etc etc... Clicking the button once should give me 1 2 3 4 5 6 7 8 9 10 Clicking again should give me 11 ... 20 and so on. How do I make this happen? I have a label named "labDisp" and a button "btnShow" on the form. Thank you.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Easy - an array is a valid source for a repeater ( and that's all you need here, so why use anything heavier ? ), so store the index you're up to in viewstate, then grab the array you need from the array of arrays and make it the data source for a repeater. Ooops - forget that if you're not doing a web page. Instead, just pass the arrays to a datagrid. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      1 Reply Last reply
      0
      • C crushinghellhammer

        I have what should be a simple problem, but I'm not able to figure it out. Suppose I have a 5 by 10 array. I populate the array, and now want to display this on a form. The array is populated in a separate codefile, which passes the array to the main form file. When I click on a button, I want to be able to see each row of the array i.e if the array is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 etc etc... Clicking the button once should give me 1 2 3 4 5 6 7 8 9 10 Clicking again should give me 11 ... 20 and so on. How do I make this happen? I have a label named "labDisp" and a button "btnShow" on the form. Thank you.

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        In your form class set up a member variable like:

        private int currentIndex = -1; // before the start of the array

        In your button click event handler:

        currentIndex++;
        if (currentIndex==5) // Don't run off the end of the array
        currentIndex = 0; // Reset to the start

        // Build the label text
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<9; i++)
        {
        sb.Append(arrayObject[currentIndex, i].ToString());
        sb.Append(" ");
        }
        labDisp.Text = sb.ToString();

        I'm assuming your array is called "arrayObject" since you didn't mention it anywhere. --Colin Mackay--

        EuroCPian Spring 2004 Get Together[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups