[Gambas-user] How to dynamically add & populate variable number of tabs at runtime?

T Lee Davidson t.lee.davidson at ...626...
Wed Apr 19 01:58:06 CEST 2017


Hello Folks,

I have been trying to figure out how to, at runtime, create a variable number of new tabs in a TabStrip, populate those tabs 
with Controls, and then be able to reference those controls, all dynamically.

There seems to be little information available as to how to 1) dynamically create controls, and 2) reference dynamically named 
controls after creation.

Even with just a simple experiment, I cannot get a GridView to display in a new tab. The Form has been given, at design-time, a 
TabStrip and two buttons. The tabs are 'closable'. One button, 'btnAddTab', creates a new tab and a GridView with the new, 
current tab as parent. (At least that's what I think it is doing.) The other button, 'btnTabInfo', displays info about the 
currently selected tab.

And, I am assuming the GridViews need to have unique names.

[code]
' Gambas class file


Public Sub btnAddTab_Click()
   Dim hGridView As GridView

   TabStrip1.Count += 1
   TabStrip1.Text = "Tab " & TabStrip1.Index
   hGridView = New GridView(TabStrip1) As "GridView" & TabStrip1.Index
   hGridView.Show
   TabStrip1.Refresh

End

Public Sub btnTabInfo_Click()

   Print TabStrip1.Children[0].Name
   Print TabStrip1.Children[0].Enabled
   Print TabStrip1.Children[0].Visible

End

Public Sub TabStrip1_Close(Index As Integer)

   TabStrip1.Index = Index
'   TabStrip1.Current.Children[0].Delete() 'Comment out to test if tab is empty
   TabStrip1.Current.Delete()

End
[/code]


Tab creation works, but the GridView control does not display. Any attempt to close a tab without first deleting its children 
causes an exception, showing that the tab is indeed being populated with a child control. Clicking on btnTabInfo for "Tab 1" gives:
GridView1
True
True

So, the program is doing at least some of what I've told it to. I'm obviously not telling it the right thing.

How does one:
1. Create new controls and make them visible?
2. Reference new controls after creation [ie. (de-)reference a string as a the name of a control]?


-- 
Lee





More information about the User mailing list