I'm working on C# with COM. I have a COM OLE control that I wish to create on the form as control array during runtime, as the number of cotrols depends on the number of files in the corresponding folder. How do I go about it? I'm attaching a pic of the form as to how I want it to be.
A control array is just an array of controls, which you create like any other array. You'd declare the array at the class level and then create the object when you know the size, e.g.
Code:
private Button[,] buttons;
private void CreateButtonArray(int rowCount, int columnCount)
{
this.buttons = new Button[rowCount, columnCount];
}
You could then use loops to populate the array.
That said, I probably suggest that you use a TableLayoutPanel to lay out the controls on the form. You can then simply add the control to the panel and it will grow automatically as required, or you can place them explicitly. You can then loop through the rows and columns of the TLP to populate the 2D array, or you can just forget the array altogether and just access the controls by row and column in the TLP.