Swap different types of ContainerControls

Is there a way to swap different types of ContainerControls?

I have a project where I have a listbox as a project browser.
Somewhere else I have a PagePanel with two pages. When there is no selection in the listbox, page 0 is displayed. When there is a selection, page 1 is displayed. This way I have a nice clean window, when nothing is selected. Only a label is shown “Select an item in the browser”… or something like that…

When there is a selection I check what type of panel should be displayed. I have stored that somewhere in the RowTag in the listbox.

Now I have a bunch of panels

  • ProjectData panel, to show/edit project settings
  • ClientData panel, to show/edit client’s details
  • MediaData panel, to show a list of media… like some sort of media library
    …and so on.

The thing is, that I want to swap the panel according to what I have selected in the list (browser).
I don’t want instances of these panels laying around when not in use. I did try to add more pages to the PagePanel control. But this way I had too many instances.
So, I close them when I change to another panel. But when I re-open a panel I got an error that I cannot embed a closed ContainerControl. So, somehow I need to re-instantiate the panel, right?
But re-instantiating a control at run-time is not possible… as far as I know.

In my listbox I assign a class to the rowtag. In this class I have properties like

  • Panel --> this is where I can store an instance of the Container Control (but this keeps too many instances “alive”)
  • dataType --> this is to identify the type of data the browser-item represents. So, when selecting it, I know what kind of data I have to pull from my database.
  • recordID --> in case a browser item refers to a record in my database.
    …and some other properties I need

It would be nice to add a windowProperty as ContainerControl named “CurrentPanel”
And do something like this:
Embed this property in the PagePanel.
Then:

CurrentPanel = new ContainerControl( mySelectedPanel ) 

or something like that…

Instantiate the container controls depending on conditions. No need to drag all of them in a pagepanel.

It is. That’s one of the reasons for having a ContainerControl.

That should work. You’re going in the right direction.

It was not possible to just embed a window property to a RectControl in the window and just swap the ContainerControls by just simply assigning another ContainerControl to the property.

However, I think I figured it out…
I had to actually close the property (first checking if it was not nil, of course)
Then, I had to assign a new panel to the property and re-embed it. It was actually not too hard. Sometimes one might think of more complex solutions than necessary. :slight_smile:

Below is an image of the example app, and here is a link to the XojoBinary test project. Just in case one might need it for inspiration in the future.

Screenshot of an example app