emi_sastra
asked on
How to Create Control Array Dynamically at Run Time?
Hi,
I have a procedure to create control array at run time. But it still has error when try to create it.
In my form, I have a label "lblDuplicate" control array index =0 and combobox call cbodata.
I call :
Create_LabelArray Me, lblDuplicate(1), 1, cboData, Frame1
in module:
Public Sub Create_Label_Control_Array (frmFormNa me As Object, _
lblNameToCreate As Label, _
intLabelIndex As Integer, _
objClone As Object, _
fraName As Object)
' Set lblNameToCreate = frmFormName.Controls.Add(" VB.Label", strLabelName)
Load lblNameToCreate(intLabelIn dex)
Set lblNameToCreate(intLabelIn dex).Conta iner = fraName
Set lblNameToCreate(intLabelIn dex).Font = objClone.Font
If TypeOf objClone Is ComboBox Then
lblNameToCreate(intLabelIn dex).Top = objClone.Top + 20
Else
lblNameToCreate(intLabelIn dex).Top = objClone.Top + 50
End If
lblNameToCreate(intLabelIn dex).Left = objClone.Left
lblNameToCreate(intLabelIn dex).Heigh t = objClone.Height - 60
lblNameToCreate(intLabelIn dex).Width = objClone.Width
lblNameToCreate(intLabelIn dex).Appea rance = 0
lblNameToCreate(intLabelIn dex).Borde rStyle = 1
lblNameToCreate(intLabelIn dex).Visib le = True
End Sub
At complile time it shows : "Wrong argument".
Please help how to solve this.
Thank you.
I have a procedure to create control array at run time. But it still has error when try to create it.
In my form, I have a label "lblDuplicate" control array index =0 and combobox call cbodata.
I call :
Create_LabelArray Me, lblDuplicate(1), 1, cboData, Frame1
in module:
Public Sub Create_Label_Control_Array
lblNameToCreate As Label, _
intLabelIndex As Integer, _
objClone As Object, _
fraName As Object)
' Set lblNameToCreate = frmFormName.Controls.Add("
Load lblNameToCreate(intLabelIn
Set lblNameToCreate(intLabelIn
Set lblNameToCreate(intLabelIn
If TypeOf objClone Is ComboBox Then
lblNameToCreate(intLabelIn
Else
lblNameToCreate(intLabelIn
End If
lblNameToCreate(intLabelIn
lblNameToCreate(intLabelIn
lblNameToCreate(intLabelIn
lblNameToCreate(intLabelIn
lblNameToCreate(intLabelIn
lblNameToCreate(intLabelIn
End Sub
At complile time it shows : "Wrong argument".
Please help how to solve this.
Thank you.
AFAIK, you can only create a control array at design time. I'm pretty sure that fact is in the documentation.
ASKER
Try this link:
http://www.vbexplorer.com/VBExplorer/vb_feature/april2000/april2000.asp
Then you will know it, It can or not.
Thank you.
http://www.vbexplorer.com/VBExplorer/vb_feature/april2000/april2000.asp
Then you will know it, It can or not.
Thank you.
There is a discussion of control arrays at
http://msdn2.microsoft.com/en-us/library/kxt4418a(VS.71).aspx
This document seems to verify that control arrays are no longer supported in vb.net. However, it gives you a way to kind of simulate control arrays.
Good luck.
http://msdn2.microsoft.com/en-us/library/kxt4418a(VS.71).aspx
This document seems to verify that control arrays are no longer supported in vb.net. However, it gives you a way to kind of simulate control arrays.
Good luck.
ASKER
Thanks for the link.
How about my code there?
What should be changed to make it works.
Thank you.
How about my code there?
What should be changed to make it works.
Thank you.
.... I didn't follow all these linkes but....
You can copy a control at runtime. You could place what ever controls you want on a form and copy these to create new ones. You can keep the originals invisible and stack them at the bottom of the form. Copy and use them as needed.
Scott C
You can copy a control at runtime. You could place what ever controls you want on a form and copy these to create new ones. You can keep the originals invisible and stack them at the bottom of the form. Copy and use them as needed.
Scott C
you can do something like that
Create_Label_Control_Array Me, lblDuplicate, 1, cboData, Frame1
Public Sub Create_Label_Control_Array (frmFormNa me As Object, _
lblNameToCreate As ojbect, _
intLabelIndex As Integer, _
objClone As Object, _
fraName As Object)
' Set lblNameToCreate = frmFormName.Controls.Add(" VB.Label", strLabelName)
Load lblNameToCreate(intLabelIn dex)
Set lblNameToCreate(intLabelIn dex).Conta iner = fraName
Set lblNameToCreate(intLabelIn dex).Font = objClone.Font
If TypeOf objClone Is ComboBox Then
lblNameToCreate(intLabelIn dex).Top = objClone.Top + 20
Else
lblNameToCreate(intLabelIn dex).Top = objClone.Top + 50
End If
lblNameToCreate(intLabelIn dex).Left = objClone.Left
lblNameToCreate(intLabelIn dex).Heigh t = objClone.Height - 60
lblNameToCreate(intLabelIn dex).Width = objClone.Width
lblNameToCreate(intLabelIn dex).Appea rance = 0
lblNameToCreate(intLabelIn dex).Borde rStyle = 1
lblNameToCreate(intLabelIn dex).Visib le = True
End Sub
Create_Label_Control_Array
Public Sub Create_Label_Control_Array
lblNameToCreate As ojbect, _
intLabelIndex As Integer, _
objClone As Object, _
fraName As Object)
' Set lblNameToCreate = frmFormName.Controls.Add("
Load lblNameToCreate(intLabelIn
Set lblNameToCreate(intLabelIn
Set lblNameToCreate(intLabelIn
If TypeOf objClone Is ComboBox Then
lblNameToCreate(intLabelIn
Else
lblNameToCreate(intLabelIn
End If
lblNameToCreate(intLabelIn
lblNameToCreate(intLabelIn
lblNameToCreate(intLabelIn
lblNameToCreate(intLabelIn
lblNameToCreate(intLabelIn
lblNameToCreate(intLabelIn
End Sub
lblNameToCreate As ojbect
should be
lblNameToCreate As object
should be
lblNameToCreate As object
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
It solve my problem.
Thank you very much.
Thank you very much.