borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (PictureBox with scrollbar)Next Topic (I need help) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Add Controls at Runtime
Poster Message
holyburak
Level: Guest


icon Add Controls at Runtime

Hi everybody!

i wrote a software consisting simply an unbound grid
and a command button on a form.I want to convert it to
an excel like multiple sheet application.(I dont ask flexible grid etc.)
Is there a way to instantiate a control at runtime
so to put it on a new sheet?(For example in a tabbed control)

Thanks For Your Interest.

Burak Ulker


[Edited by holyburak on 08-02-2003 at 04:41 AM GMT]

07-02-2003 at 08:50 AM
| Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: excel like multiple sheets

i'm not sure what you are asking...

' If you are adding an ActiveX control at run-time that is
' not referenced in your project, you need to declare it
' as VBControlExtender.
Dim WithEvents ctlDynamic As VBControlExtender
Dim WithEvents ctlText As VB.TextBox
Dim WithEvents ctlCommand As VB.CommandButton


Private Sub ctlCommand_Click()
  ctlText.Text = "You Clicked the Command button"
End Sub

Private Sub ctlDynamic_ObjectEvent(Info As EventInfo)
' test for the click event of the TreeView
  If Info.Name = "Click" Then
    ctlText.Text = "You clicked " _
     & ctlDynamic.object.selecteditem.Text
  End If
End Sub

Private Sub Form_Load()
  Dim i As Integer
  ' Add the license for the treeview to the license collection.
  ' If the license is already in the collection you will get
  ' the run-time error number 732.
  Licenses.Add "MSComctlLib.TreeCtrl"
  ' Dynamically add a TreeView control to the form.
  ' If you want the control to be added to a different
  ' container such as a Frame or PictureBox, you use the third
  ' parameter of the Controls.Add to specify the container.
  Set ctlDynamic = Controls.Add("MSComctlLib.TreeCtrl", _
    "myctl", Form1)
  ' set the location and size of the control.
  ctlDynamic.Move 1, 1, 2500, 3500
  ' Add some nodes to the control.
  For i = 1 To 10
    ctlDynamic.object.Nodes.Add Key:="Test" & Str(i), Text:="Test" _
      & Str(i)
    ctlDynamic.object.Nodes.Add Relative:="Test" & Str(i), _
      Relationship:=4, Text:="TestChild" & Str(i)
  Next i
  ' Make the control visible.
  ctlDynamic.Visible = True
  ' add a textbox
  Set ctlText = Controls.Add("VB.TextBox", "ctlText1", Form1)
  ' Set the location and size of the textbox
  ctlText.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
    1, 2500, 100
  ' Change the backcolor.
  ctlText.BackColor = vbYellow
  ' Make it visible
  ctlText.Visible = True
  ' Add a CommandButton.
  Set ctlCommand = Controls.Add("VB.CommandButton", _
    "ctlCommand1", Form1)
  ' Set the location and size of the CommandButton.
  ctlCommand.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
    ctlText.Height + 50, 1500, 500
  ' Set the caption
  ctlCommand.Caption = "Click Me"
  ' Make it visible
  ctlCommand.Visible = True
End Sub


this code is for creating controls during runtime, which actually came from this link:

http://www.andreavb.com/forum/viewtopic.php?TopicID=818&page=0#2361

check it out if i got it right. there's a good discussion already at that link.

just post back and clarify.  

____________________________
Been busy trying to take a second degree <--it's not working out...

07-02-2003 at 02:49 PM
View Profile Send Email to User Show All Posts | Quote Reply
holyburak
Level: Guest

icon Re: Add Controls at Runtime

Adding controls at runtime is what i ask actually.
i send Thanks of mountains to you and JLRodger but
your(microsoft's) code failed in the first line saying;

"User Defined Type Not Defined" for ->
Dim WithEvents ctlDynamic As VBControlExtender

i mean:
in excel when you add a new sheet, it must be adding a new
flexible grid (and when you delete the sheet etc.)i want to do the same.

Anyway thanks again.    

08-02-2003 at 09:48 AM
| Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: Add Controls at Runtime

the error with the ctldynamic is an object, actually an activex control that isn't referenced in your  project,hence the comment

' If you are adding an ActiveX control at run-time that is
' not referenced in your project, you need to declare it
' as VBControlExtender.


next, the control being added was a treeview... from this part...


..............
Private Sub Form_Load()
  Dim i As Integer
  ' Add the license for the treeview to the license collection.
  ' If the license is already in the collection you will get
  ' the run-time error number 732.
  Licenses.Add "MSComctlLib.TreeCtrl"
  ' Dynamically add a TreeView control to the form.
  ' If you want the control to be added to a different
  ' container such as a Frame or PictureBox, you use the third
  ' parameter of the Controls.Add to specify the container.
  Set ctlDynamic = Controls.Add("MSComctlLib.TreeCtrl", _
    "myctl", Form1)
  ' set the location and size of the control.
  ctlDynamic.Move 1, 1, 2500, 3500
  ' Add some nodes to the control.
  For i = 1 To 10
    ctlDynamic.object.Nodes.Add Key:="Test" & Str(i), Text:="Test" _
      & Str(i)
    ctlDynamic.object.Nodes.Add Relative:="Test" & Str(i), _
      Relationship:=4, Text:="TestChild" & Str(i)
.............
  

now you'd have to set reference to the object flexgrid...

which i hope JL knows how to access...

but try for now

MSFLXGRD.FlexCtrl

but i know that that wouldn't be accurate...

so please try waiting for JL to confirm if he knows how.

sorry..  

____________________________
Been busy trying to take a second degree <--it's not working out...

08-02-2003 at 02:11 PM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: Add Controls at Runtime

The following was on microsoft's page:


Private Sub ctlDynamic_ObjectEvent(Info As EventInfo)
   ' test for the click event of the TreeView
   If Info.Name = "Click" Then
'Modified, did use a text box to display
      debug.print = "You clicked " & ctlDynamic.object.selecteditem.Text
   End If
End Sub



____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

08-02-2003 at 09:01 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: Add Controls at Runtime

JL, what i meant to ask you was how tostate the control 'msflexgrid' in the code...

if

MSComctlLib.TreeCtrl

was the code name used to add a treeview, then what shoul be the format of the flexgrid?

i don't know how...

____________________________
Been busy trying to take a second degree <--it's not working out...

10-02-2003 at 06:49 AM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: Add Controls at Runtime

Didn't see anything online, and MSFlexGrid, MSHFlexGrid, Flexgrid don't work... So I have no clue. Might be easier just to put it on the form with Visible=false (perhaps in a control array).

____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

10-02-2003 at 07:26 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: Add Controls at Runtime

this seems to be the reference to a flexgrid:

MSFlexGridLib.MSFlexGrid

anyway you need to add "Microsoft FlexGrid Control 6.0" in the controls reference...

____________________________
AndreaVB

10-02-2003 at 07:37 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB General : Add Controls at Runtime
Previous Topic (PictureBox with scrollbar)Next Topic (I need help) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder