Indexing Multiple ContainerControls

I have a small ContainerControl (160x143) called groupCtr which contains just a couple of other controls. I need to place 15 of these CC’s on my window. I have created a window-scoped property (cc As groupCtr). In a loop I can create the CC’s by

for i As integer = 0 to 14 cc = New groupCtr(i) cc.embedWithin(Self, x, y) next
The passed param is to create an index property in the CC’s constructor.
OK great! Now. I will need to put data into various of these CC’s as the program progresses.
How do I identify the CC. Say I want to put someData As String in cc #6. Since I could not create an array of these containers, do I have to poll the entire list of CC’s looking for the one with index #6 each time I want to do something with one of them?
How do I identify each of these 15 cc’s on my window?

Thanks

You’re not using an array, and you probably should be. Your window property should look like:

cc() as grouptCtr

Then you append the new CCs to the array:

for i As integer = 0 to 14 dim newCC as ContainerControl = New groupCtr(i) newCC.embedWithin(Self, x, y) cc.Append( newCC ) next

Which will allow you to access them by index:

dim myCC as groupCtr = cc(13) myCC.SomeProperty = X

Thank you, Anthony, for your reply. Something got messed up with this thread and I didn’t see you response until now.

for i As integer = 0 to 14 dim newCC as ContainerControl = New groupCtr(i) newCC.embedWithin(Self, x, y) cc.Append( newCC ) //runtime error "Parameters are not compatible with this function next
The issue is that you can’t make an array of container controls
That’s what I was bumping up against before.

Why not?

is cc an array? This should definitely work.

I just did the following…

Add a new ContainerControl to the project

Add a property to the window:
cc() as ContainerControl

In Window.Open:
cc.append( new ContainerControl1 )

The problem is in the defition. Should be As ContainerControl, not As groupCtr

Then you’ll cast what you need to groupCtr

dim myCC as GroupCtr = cc(10)

And you may need an explicit cast:

dim myCC as GroupCtr = GroupCtr(cc(10))

Thank you Anthony and Tim. I keep getting compiler errors when I try cc() As ContainerControl and I thought I had read somewhere that CC’s could not be arrays, so I may have jumped to conclusions. I will try to digest your advice and make this work.
Thanks again for your help

As a quick test, I created a container, GroupCtr. I added a property to the window, cc() as GroupCtr. In Window.Open, i put:

dim newCC as GroupCtr
newCC = new GroupCtr
cc.Append newCC

Runs without error. If all the containers in the array are the same type, then make the array that type and it will make your code easier. You can do things like

cc(10).someCustomMethod
dim i as integer = cc(10).myCoolIntegerProperty
for i = 0 to ubound(cc)
   if cc(i).ID = 5 then
       ...
   end
next

ContainerControls are really just like any other class/object.

[quote=381806:@Roger Clary]Thank you Anthony and Tim. I keep getting compiler errors when I try cc() As ContainerControl and I thought I had read somewhere that CC’s could not be arrays, so I may have jumped to conclusions. I will try to digest your advice and make this work.
Thanks again for your help[/quote]
I think the limitation you’re remembering is that you cannot (or could not in the past, not sure about now) make a ControlSet (fka ControlArray) of ContainerControls.

Yes, Julia, I think that was my confusion.

With your last example, Tim, I think I’ve got it to where I can make this work.
Thanks again to all who responded. I’m really appreciating this forum tonight :slight_smile:

Yes, Julia, I think that was my confusion.

With your last example, Tim, I think I’ve got it to where I can make this work.
Thanks again to all who responded. I’m really appreciating this forum tonight :slight_smile: