Making an indexed control array?

I know I’m a little late to this party, but this solution will work:

Make a global array:

    TextBox[] myTextBox;

Then in your object’s constructor, after the call to

    InitializeComponent();

initialize your array:

    myTextBox = new TextBox[] {TextBox1, TextBox2, ... };

Now you can iterate your array of controls:

    for(int i = 0; i < myTextBox.Length; i++)
        myTextBox[i].Text = "OMG IT WORKS!!!";

I hope this helps!

Pete

Leave a Comment