I have a class which creates a two dimensional array of objects that hold an int. When I populate this array with int objects, I'd like to pass the array which I call a grid to a form holding a matrix of labels. I then want to output the 2 dim array using ToString val by val to each label on the Form.
I can instantiate the Grid object in the Form Class and access the methods in the Grid class, but when I try to use the [, ] operator I get the error "Cannot apply indexing with [] to an expression of type 'grid'.
Expand|Select|Wrap|Line Numbers
- private void fillGrid(SudokuGrid grid)
- {
- int i = 0;
- int j = 0;
- foreach (Control control in tableLayoutPanel1.Controls)
- {
- Label originalLabel = control as Label;
- if (originalLabel != null)
- {
- originalLabel.Text = grid[i,j].val.ToString();
- //originalLabel.ForeColor = originalLabel.BackColor;
- j++;
- if ((j == 9) && (i < 9))
- {
- i++;
- j = 0;
- }
- }
- }
- }
Thanks,
H