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


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to