Since VB6 is now fading into history, many programmers might not remember that VB6 had a feature called "control arrays" that let you simply drag and drop multiple controls onto a form and then reference the individual controls as an array. For example, if you wanted to make a whole group of Label components invisible, you could just loop through your array and set the Visible property to False. It was a really popular feature because it was just so useful!
I wrote the first VisualBasic.About.com article about how to program something like VB6 control arrays in VB.NET in 2004. I had no idea back then that it would become the most popular single topic on the site. I still get questions about how to solve this problem.
It's a significant problem because, in general, there is no way to exactly duplicate the VB6 control array. It really depends on what you value most.
- The ease of adding them to your program.
- The simplicity of changing properties for controls in the array at runtime.
- The uncomplicated concept of managing controls as an array.
You can get all of these with .NET ... but not all at once. You can add a class to your project that allows you to add and delete controls in an array, but it's nothing like the simplicity of VB6.
I have been answering questions about control arrays by referring readers to the seven articles here on the site. That's still a good way to do it, but I decided that it would be a lot easier for readers to be able to download a single file that has everything in it. If you need to know how to program control arrays in VB.NET, one of these ideas should work for you.
Download the PDF file of all seven articles here.
It's also only fair that I give one final acknowledgement to the contributors who provided the ideas, and often the text itself, for these great articles. Here are the people who did it:
- Frank Bugeja
- Charlie Weisel
- Selden McCabe
- William Benton
- Patrick Krawec
- Clif Gay

