Multiple instances of same Containercontrol in a coloumn to window

Hello,
I have a custom containercontrol “cc2” and i want to add instances of it with different values to window at runtime one at time vertically, each one below the previous one like a coloumn.
before adding containercontrol to the window i am assigning values to it’s properties .

but with this code only the first instance is being added .Can you please pointout where i went wrong.Thankyou

method-CalculateVerticalPosition(counter As Integer)
Return (Counter - 1) * 210

property-instanceCounter as Integer

CreateAndAddContainer(container As ContainerControl2)

Dim instanceCounter As Integer = 0
Dim containerArray() As ContainerControl2

instanceCounter = instanceCounter + 1
container.Title = “Container2_” + Str(instanceCounter)

containerArray.Append(container)

Dim nextVerticalPosition As Integer = CalculateVerticalPosition(instanceCounter)

container.Left = 100 ’ Set the left position as needed
container.Top = nextVerticalPosition

Container2.EmbedWithin(Window1, container.Left, container.Top)

You’re not creating a new instance of container every time? That would mean that every instance in ContainerArray and window1 would be pointing to the exact same container instance.

1 Like

@Christian_Schmitz’s container control list works well for me and with some minor changes doesn’t require any plug-ins to work cross-platform:

You can download the example program from the MBS website, no purchase necessary.

Thank you for responding Mr.Tim and Ms.Julia

Mr.Tim i don’t quite understand what you mean,can you please elaborate ?

Ms.Julia Thank you i will try it

If you want an instance of an object, you have to create it either by dragging from the Library onto your layout (gives ypu one instance), or by using new. Just declaring a property which can hold a reference to the object gives you no instances at all. So:

Var  myPtr as cc2                   // Can hold a reference to an instance
myPtr = new cc2                     // Creates an instance

By the way, if you post code here, please do this:

  1. Add the code to your post
  2. Select it all with the mouse
  3. Click on the </> button

cc2 is a subclass of class1 which has a method called Hnd1.

Hnd1 method has this code.

Dim container2 As New cc2
Window1.CreateAndAddContainer(container2)

i am trying to create object in hnd1 method and use it as argument in CreateAndAddContainer method in window to embed it to the window.

is it possible?