Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic control creation again.

Status
Not open for further replies.

nhc

Programmer
Apr 3, 2000
10
AU
I'm actually still struggling with a problem I posted earlier. My original problem was the creation on controls at runtime without having to use control arrays (As I was placing a usercontrol within itself to form a kind of tree).<br><br>This was answered by the user GTO, they pointed me to a HOWTO on dynamic control creation.<br><br>An example of dynamic control creation:<br><br>&nbsp;&nbsp;&nbsp;Dim WithEvents ctlDynamic As VBControlExtender<br><br>&nbsp;&nbsp;&nbsp;Private sub Form1_Load()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Licenses.Add &quot;MSComctlLib.TreeCtrl&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set ctlDynamic = Controls.Add (&quot;MSComctlLib.TreeCtrl&quot;,&quot;myctl&quot;, Form1)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ctlDynamic.Move 1, 1, 2500, 3500<br>&nbsp;&nbsp;&nbsp;end sub<br><br>&nbsp;&nbsp;&nbsp;Private Sub ctlDynamic_ObjectEvent(Info As EventInfo)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' test for the click event of the TreeView<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If Info.Name = &quot;Click&quot; Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ctlText.Text = &quot;You clicked &quot; & ctlDynamic.object.selecteditem.Text<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;End Sub<br><br>The problem I have is that although now I can create the controls at runtime I can only create one. My usercontrol needs to be able to create multiple children(with each child able to do the same). So I guess I'm asking how do I create a control array dynamically, as the following line does not work.<br><br>private withevents ctlDynamicArray() as VBControlExtender<br><br>This seems to be the last snag in my control (I shouldn't have said that) so any feedback/solutions would be very very greatly appreciated.<br><br>Nick. <p>Nicholas Clark<br><a href=mailto:nhc@operamail.com>nhc@operamail.com</a><br><a href= > </a><br>
 
Is this any help?<br><br>Private Sub cmdBtn_Click(Index As Integer)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim btn As CommandButton<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim iIndex As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;iIndex = cmdBtn.Count<br>&nbsp;&nbsp;&nbsp;&nbsp;If iIndex &lt;= 32767 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Load cmdBtn(iIndex)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set btn = cmdBtn(iIndex)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;With btn<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Top = cmdBtn(iIndex - 1).Top + 620<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Caption = &quot;Command&quot; & iIndex + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Visible = True<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End With<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set btn = Nothing<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br><br>End Sub<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top