Add new TabPanel using code

I am currently add in a blank tabpanel and put it in the right place and when opening the window, add in the tab based on permission on a table.

What i would like to do is use code to add in tabpanel (not the tab in the panel) and then attach the code on change event of the tabpanel.

you want to add the entire tab panel control on the fly ?
and add code to the tab panel that handles the changing of the tabs ?

Yes… to both… i already know how to do it if the tabpanel is there and the change event us already attach to the tabpanel

There are at least 3 ways this could be done

First way

  1. create a container control
  2. put an instance of the tabpanel on that container
    now you can dynamically add instances of that container as many times as you want
  3. you can add events, methods & properties (i’d use computed properties) to the container control to expose all the events, properties and methods of the tab panel to the code that uses the container
    And now you can place instances at design time or runtime
    And you can hook up the events & methods just as if it were JUST a tabPanel

There are some limitations to this approach though as a containerControls EmbedWithinPanel needs the actual tabPenel not a container so it wont work without some extra work :frowning:

Second way
Put one instance of a tabControl on a layout and make it a control group
Now you can create new instances of tabpanels that are part of that group
The downside is that each of the instances shares ONE event handler so trying to add an event handler at runtime messes with all of them

Third way
I cant write about here
Undocumented API’s and all that
Unfortunately its also the most suitable

I’m not sure if the name changed, but if you’re talking of the control SETS in 2019r1.1 and earlier, then I’m not sure why everyone says that events for control sets are problematic?
The shared event method has an index that passes the control # so you can tell which control called it. If you use the index you can just deal with the control that called the event, or if you ignore it, you can deal with all of them. Very flexible and works great.

If youre going to use the index to do different things you might as well just use separate instances

Basically its a non-OO way to do OO like things

EDIT : ideally you’d be able to do

   dim tp as new TabPanel
   // set properties like size width etc
   self.addcontrol tp
   // now use add handlers to set up whatever event handlers you want

and the control just exists & is set up as you expect

How do you figure? I have a control set of a variable number of checkboxes, depending on a number of factors. I think with separate instances it would be a lot more work to create each one on the fly (can that even be done?), with it’s associated properties and events…

Suppose in each of several scenarios I want 3 check boxes
So they are index 0 1 and 2
In one case checkbox index 0 represents “property A”, checkbox index 1 represents “property B”, checkbox index 2 represents “property C”

In another checkbox index 0 represents “property C”, checkbox index 1 represents “property A”, checkbox index 2 represents “property B”

index isnt adequate without some other info (the tag etc) to know which is which
In fact index isnt terribly useful at all
That is my usual experience - others may vary

Option # 3 undocumented APIS etc :stuck_out_tongue:
see MBS Blog - Tip of day: Dynamically add webimageview to webpage

1 Like

Since I added them in code, I’m completely in charge of which checkbox is at which index, so no problem in my case. And having a single event handler for all of them is nice and terse (the way I like it!) :wink:

ahhh … i see what is missing in my code… i do the “dim tp as new TabPanel” but didn’t know i need to do the “self.addcontrol tp”

that api literally doesnt exist so it wont work in any case

the self.addcontrol only work on web and ios but not desktop

yeah you’d have to poke around like christian did to see if the is some other API :slight_smile: