ContainerControl inside a TabPanel

i’ve created a TabPanel in a window and 2 buttons that i use to add and remove tabs dinamically to the tabpanel.
Every time a new tab is created a ContainerControl is attached to the tab using this code that i found on the manual :

MainTab.Append("New Tab") Dim tabNum As Integer tabNum = MainTab.PanelCount - 1 Dim cc As New MyContainer cc.EmbedWithinPanel(MainTab, tabNum)

So if the user clicks 4 times on the add button i end up having a tabpanel with 4 tabs and each have a containercontrol called cc.
Let’s say that the cointainercontrol has only a text editable box where the user can write something. He can move on every tab and write something different on every text box.

Now my question is : How can i retrieve data inside every text box ?
According to the code ALL the containerControl are called CC so i can i know what is written in the containercontrol in tab1 or tab2 or tab3 etc etc.


You’ll need to retain a reference to your newly created container. Right now you Dim it in the method and then it goes away when the method ends so you’ll have no way to access it.

Instead use a property. An array property like this could work:

TabContainer() As MyContainer

Then your code would instead be:

MainTab.Append("New Tab") Dim tabNum As Integer tabNum = MainTab.PanelCount - 1 Dim cc As New MyContainer TabContainer.Append(cc) // save reference to your new container cc.EmbedWithinPanel(MainTab, tabNum)

Outside of the method you could refer to the container using the array:

Dim value As String = TabContainer(0).MyTextField.Text

You’ll need other code to remove containers from the array when the tab is closed.

A Dictionary could also be used instead of an array.

Actually, you shouldn’t talk to the controls inside of the ContainerControl, you should be asking the ContainerControl for information (or data)… On the ContainerControl, create a method “MyTextFieldValue” that returns Text

MyTextFieldValue return self.MyTextField.Text.ToText myTextFieldValue

and then your code, to get the text, would be

DIM value As Text = TabContainer(0).MyTextFieldValue

replace 0 with whatever TabContainer you are going for… Good luck :slight_smile:

I agree, but you have to walk before you can run.

I thought was “you have to run before you can crawl”? :wink:

Thanks a lot to both of you!
I’m using the array idea and it is working well but to avoid memory leak i would like to know :
When the user delete a tab from the tabpanel i have to delete the relative ContainerControl in the array of ContainerControls. Is enough to delete the element in the array or i should Close the ContainerControl and then remove the element of the array.

Using your example :

TabContainer.Remove(MainTab.Value) is enough

or should i use

and then