Dynamic ContainerControl

Hi everyone,

i created a ContainerControl with a Textfield and 2 PushButtons beside named + and -.

Should work like this:

  • User can add several filter (Container)
  • the first Container shows only the + Button, which adds a new Container under the one, which sent the Add-Command and so on (optional: if you only want to add max. 5 Container, then the Container at Index 5 shows only the - Button)
  • all Containers with Index > first Container shows both Buttons (+ and -)
  • if a user delete Container 5 then the following Container should automatically refresh their position (fill the space of the removed Container 5)

Does anyone realized something like that in past and can give me some input? Tutorial-like?

Xojo does this in their Enumeration-Editor.

I know the ContainerControl Webinar, but there it is not possible to delete a Container at Position x or add a Container at Position x.


Hi, I use a ContainerControl just like you used with same problem, when you press “minus” button the control raise an event to parent control (lets say window1) and the window1 remove the “index” of the containerControl with a timer, why? to give time to exit of event function before “delete” the index. When you add a ContainerControl to array, set a property with the index and add a event (example: “Remove(index As Integer)”) with the index to remove.

In window1, add an integer property and a timer, add next code to “Remove” event of ControlContainer Instance (with AddHandler):

mIndexToRemove= index Timer1.Mode= Timer.ModeSingle

Code for Action event of Timer1:

[code]Dim item As ControlContainerClassYouCreate= mArrayOfcontrols(mIndexToRemove)
item.Visible= False
item= Nil

mArrayOfcontrols.Remove mIndexToRemove

're-display your controls here, for empty spaces…

Thanks for your answer Bernardo,
will that be a clean solution? Something inside me says, do not use Timer, if there is no need. Maybe because of the RAM-Ressources :wink: And how does the + Button works?

I have implemented this, but in a hierarchical way like OS X’s NSPredicateEditor:
Two container controls: FilterPanel and FilterPanelRow (the latter can also be subclassed to get different row UIs).
FilterPanel holds the FilterPanelRows in an array.
FilterPanel has the methods: AddRow, InsertRow, DeleteAllRows, DeleteRow, MoveRowToRow.
FilterPanelRow has the methods: AddChildRow, InsertChildRow, DeleteAllChildRows, DeleteChildRow, MoveChildRowToRow.
In FilterPanel.AddRow a new FilterPanelRow is added with ContainerControl.EmbedWithin.
In FilterPanel.DeleteRow the FilterPanelRow is removed from the array and then destroyed with ContainerControl.Close.

Sounds good Eli Ott. But how does the FilterPanelRow know, where to add a new FilterPanelRow? Mean the Hierarchy is 1. FilterPanel and 2. FilterPanelRow, not upsidedown.
Yes NSPredicateEditor ist exactly what i want, like this:

Add the same array mechanism which holds the FilterPanelRows in FilterPanel to FilterPanelRows for its children. Then walk the hierarchy and count including the children and the children’s children etc.

I took several attempts to develop the whole thing and only got it right, when I developed the whole thing on paper (which I normally don’t do – I’m a code-first-think-later developer…).

@Eli Ott: would you be willing to share? I’m going to need something like this very soon.

maybe this example ?

Yeah, it could be done with ControlSet, but I have many issues with this approach. The controlSet looks like an array behaves like an array but DOESN’T an array. My approach is more complicated, uses timers and AddHandles but works, you can see an example here. I use a lot, maybe could write a simple demo.

One more example is the “download containers” from/examples ,that add dynamic containers on window and after remove 1 or more recalculate position…

Sorry Eli Ott, can’t follow you. Can you please upload a sample?
Loannis, that’s not really, what i meant, because the add and delete Buttons are not within the ContainerControls…
Please Bernardo realize a sample, thank you

Unfortunately not. The code belongs to the company I work for.


I don’t remember where I looked the code, don’t finds in this forum, maybe in pro forum, anyway, here is an example, I hope help you.

Thanks Bernardo, that’s a great sample, very helpful. Good base to go on with it :slight_smile: