views:

21

answers:

1

I am new to C#.I have been thinking of adding a ButtonControlArray where i can store each button control.Here is part of my code.I am creating a 6*6 array of button Control.

ButtonControl buttonControl;
ButtonControl[,] arrayButtons = new ButtonControl[6,6];
public void createGrid()
    {            
        l = 0;            
        for (int i = 0; i < numberOfButtons; i++)
        {
            for (int k = 0; k < numberOfButtons; k++)
            {                
                buttonControl = new ButtonControl();
                buttonControl.Location = new Point(l,j);                     
                j += 55;

                arrayButtons[i, k] = buttonControl;
                //After the above statement if i print Console.WriteLine(""+arrayButtons[i,k]); i am getting only my projectname.buttoncontrol

                myGridControl.Controls.Add(buttonControl);
            }
            l += 55; j = 10;                
        }
    }

I want to access each variable in arrayButtons[][]..like in a 3*3 matrix..if i want 2nd row 1 column element..then i get something like arrayname[2][1]..same way if i want 2nd button in 2nd row how can i get..i tried doing one way but i couldnt figure it out...Can you help me out with this..

A: 

What are you having difficulty with?

If you're running into bounds checking problems, you should know that C# arrays start at zero, not one. So the button in the second row, first column is a[1,0] not a[2,1]

If you Google Control Arrays in C# you will get several good matches, including this one.

Robert Harvey