Tab Panel for Runtime Generated new tabs with Listboxes

New to Xojo- first project. I am unintentionally abusing this coding effort.

The basic task is to create a runtime configurable UI for machine techs to configure equipment. The 1st phase code testing does the following:

  1. Application has a TabPanel.
  2. 1st panel is static data always accessible. Currently, it has a single button to create new tab panels.
  3. For each button press, a new tab is to be created and populated with a listbox (or grid view type object) to display data for the User to enter about the machine process.
  4. The listbox is configured to known dimensions

The new tab panels are generated, but listbox isn’t created at runtime by the AddNewControl method (generates compiler faults). I’ve read blog articles and tested various approaches, but I am obviously abusing this code. Here’s one of the code snippets which shows the basic goal:

’ add a tab panel for a new cabinet/solenoid cfg
var tabPanelCurrentCount As Integer = tabPanel_cabinetCfg.PanelCount
var tabPanelNextIdx As Integer = tabPanelCurrentCount + 1
var tabPanelLastCreatedPanel As Integer = 0

label_nextCabIdx.text = tabPanelNextIdx.ToString

tabPanel_cabinetCfg.AddPanel(“Cabinet #” + tabPanelNextIdx.toString)

// Create and configure the ListBox
var listBox_cabCfg As New Listbox
var i as integer = 0

listBox_cabCfg.ColumnCount = 21
for i = 1 to 49
listBox_cabCfg.AddRowAt(i, i.toString)
next i

'listBox_cabCfg.RowCount = 49
listBox_cabCfg.HasHeader = True
listBox_cabCfg.Width = Me.Width - 20 // Adjust with window size
listBox_cabCfg.Height = Me.Height - 40
listBox_cabCfg.Left = 10
listBox_cabCfg.Top = 10

tabPanelLastCreatedPanel = tabPanel_cabinetCfg.LastAddedPanelIndex
if tabPanelLastCreatedPanel <> 0 then
tabPanelLastCreatedPanel.AddControl(listBox_cabCfg)
Me.AddControl(listBox_cabCfg)
end if

I could use a hint or push in the right direction… Thanks

Use something to mimic the tab panel and then load the data into one listbox. My Trixi’s tabpanels (Xojo + Alfred) could be used as starting point.

Or mimic the tab panel and add containers with a listbox.

What does this mean, please? If you are getting errors (runtime or compile time) it helps if you post them.

Also, if posting code, please:

  1. add the code to your post
  2. highlight it with the mouse
  3. press </>

Then it will look like this:

var tabPanelCurrentCount As Integer = tabPanel_cabinetCfg.PanelCount
var tabPanelNextIdx As Integer = tabPanelCurrentCount + 1

.
whch is a lot more readable. Thanks.

1 Like

As Beatrix says.

Learn about DesktopContainer, put your ListBox in one of those (plus whatever other controls you may want), and then you can dynamically add (replicate) any number of your custom container to your new tab panels.

Works well for me.

Admittedly it’s a bit of a learning curve, but a very powerful feature.

Thank you Beatrix & Scott. I read through the DesktopContainer and did some unsuccessful test coding. It seems ideal.

After I posted this forum topic, I tripped across a Xojo Blog post that nicely walks through its use. I haven’t tried what’s in it yet, but in reading it the article ties together the things I was missing.
(Simplified: Adding User Interface Controls at Runtime – Xojo Programming Blog)

Beatrix- cool example code. I downloaded it just now. Thank you for sharing.

It’d be interesting if Xojo had a grid view type object to augment a listbox object.

1 Like

@Lee_Clore

Grid control is on the roadmap Grid Control

In your initial code you posted, you are not setting the Parent or PanelIndex. It’s quite possible your control is behind the tabpanel.

excellent! what else should i ask for? :grinning:

Yes, that crossed my mind. I thought that
tabPanelLastCreatedPanel.AddControl(listBox_cabCfg)
would attach it to the created panel. The compiler didn’t like that. Thanks!

tabPanelLastCreatedPanel is an integer. There is no connection to the panel.