Attempting to remove dynamically-added containers

Hi. I have a need for control sets in my web app. Discovered they’re not available, but I did find a useful solution in the Dynamic Container Control example. Instead of adding just one at a time per the example, I have a special need to create several containers. I found a post somewhere on the form, which works great for adding the controls. But my problem now is determining how to remove a specific one and/or all of the controls. Going by the example project, the .Close does not seem to work for me, but when I add just one as in the example, I can close one specific container no problem. I am guessing it has to do with the way I am creating the multiple containers

Here is my test of adding 4 containers (the containers have a canvas)

Dim controlsToAdd As Integer = 4

Dim test As New TestContainer

Dim r as Integer
Dim top as Integer = 25

For r = 0 to controlsToAdd - 1
  if mTestContainer(r) is nil then
    
    test.RCanText = "container " + r.ToText
    
    test.EmbedWithin(Self, me.Left + me.Width + 50, top, test.Width, test.Height)
    
    test = new TestContainer
    
    top = top + 10
  end if
Next

Do you see anything here that would prevent the closing of any one of the containers? The below is exactly from the example (modified for my test project) to attempt to close one of the containers, which is not working when adding multiple containers from the above code, but this does work when I just add one control as in the example project

If mTestContainer(0) <> Nil Then
  mTestContainer(0).Close
  mTestContainer(0) = Nil
End If

Are you sure this is True?

If mTestContainer(0) <> Nil Then

I don’t see:

mTestContainer(r) = test

in your for - next loop.

1 Like

Well that did it! You are right. I missed including that! Added it, and it works. Thanks Alberto!