Displaying Multidimensional Arrays in a Form
-
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.
-
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.
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
-
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.
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--