Home All Groups Group Topic Archive Search About

Using Control Array in User Control

Author
29 Jan 2006 5:10 PM
Jud Mel
Hello,

I am trying to create a user control containing a control array, it does not
seem to work.
Does anyone know how to do it?

Thanx.

Notice Yehuda Udi Melamed CEO, Cube18 Food Chain Franchise - Israel (
?2-6245412 È ?54-7490548 * c**@cube18.com www.Cube18.com

Author
29 Jan 2006 6:17 PM
Mike D Sutton
> I am trying to create a user control containing a control array, it does
> not seem to work.
> Does anyone know how to do it?

You'll need to provide a little more explanation about exactly what you're
trying to do; creating control arrays within a new user control and dropping
a control array of controls on a control-container user control both work
fine at design time here.
If you're trying to create a control array at runtime then you'll need to
create one of the controls you want to use and set it's .Index property to
something _at design time_, then use the Load() function to spawn new
siblings at runtime.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
29 Jan 2006 6:17 PM
Mike D Sutton
> I am trying to create a user control containing a control array, it does
> not seem to work.
> Does anyone know how to do it?

You'll need to provide a little more explanation about exactly what you're
trying to do; creating control arrays within a new user control and dropping
a control array of controls on a control-container user control both work
fine at design time here.
If you're trying to create a control array at runtime then you'll need to
create one of the controls you want to use and set it's .Index property to
something _at design time_, then use the Load() function to spawn new
siblings at runtime.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
29 Jan 2006 7:50 PM
Jud Mel
Well, I cant find a way to get to the control since the
LET\GET functions do not relate to arrays(indexes).

Here is the whole pic, so: When I use the control on a
dataRepeater, all the repeated controls function as one control (clicking
the checkBox on the control) and i can not seem to control each one by
itself. I need to create a user control such
as this one for example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconUsingDataRepeaterControl.asp
but 1 that has either a dynamic control array or a constant one.

How do you address a control through its index?

Hope U understand my needs.

Thanx..

Show quoteHide quote
"Mike D Sutton" <ED***@mvps.org> wrote in message
news:O6k%237BQJGHA.424@TK2MSFTNGP12.phx.gbl...
>> I am trying to create a user control containing a control array, it does
>> not seem to work.
>> Does anyone know how to do it?
>
> You'll need to provide a little more explanation about exactly what you're
> trying to do; creating control arrays within a new user control and
> dropping a control array of controls on a control-container user control
> both work fine at design time here.
> If you're trying to create a control array at runtime then you'll need to
> create one of the controls you want to use and set it's .Index property to
> something _at design time_, then use the Load() function to spawn new
> siblings at runtime.
> Hope this helps,
>
>    Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
Author
29 Jan 2006 7:50 PM
Jud Mel
Well, I cant find a way to get to the control since the
LET\GET functions do not relate to arrays(indexes).

Here is the whole pic, so: When I use the control on a
dataRepeater, all the repeated controls function as one control (clicking
the checkBox on the control) and i can not seem to control each one by
itself. I need to create a user control such
as this one for example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconUsingDataRepeaterControl.asp
but 1 that has either a dynamic control array or a constant one.

How do you address a control through its index?

Hope U understand my needs.

Thanx..

Show quoteHide quote
"Mike D Sutton" <ED***@mvps.org> wrote in message
news:O6k%237BQJGHA.424@TK2MSFTNGP12.phx.gbl...
>> I am trying to create a user control containing a control array, it does
>> not seem to work.
>> Does anyone know how to do it?
>
> You'll need to provide a little more explanation about exactly what you're
> trying to do; creating control arrays within a new user control and
> dropping a control array of controls on a control-container user control
> both work fine at design time here.
> If you're trying to create a control array at runtime then you'll need to
> create one of the controls you want to use and set it's .Index property to
> something _at design time_, then use the Load() function to spawn new
> siblings at runtime.
> Hope this helps,
>
>    Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
Author
30 Jan 2006 3:36 PM
Ken Halter
"Jud Mel" <i***@cube18.com> wrote in message
news:OxCYpzQJGHA.3944@tk2msftngp13.phx.gbl...
> Well, I cant find a way to get to the control since the
> LET\GET functions do not relate to arrays(indexes).

You add the code to support the Index parameter...

> Here is the whole pic, so: When I use the control on a
> dataRepeater, all the repeated controls function as one control (clicking
> the checkBox on the control) and i can not seem to control each one by
> itself. I need to create a user control such
> as this one for example:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconUsingDataRepeaterControl.asp
> but 1 that has either a dynamic control array or a constant one.
>
> How do you address a control through its index?
>
> Hope U understand my needs.
>
> Thanx..

'===========Form Code
Option Explicit

Private Sub Command1_Click()
   UserControl11.TB(0).Text = "This is Text1(0)"
   UserControl11.TB(1).Text = "This is Text1(1)"
End Sub
'===========UserControl Code
'This usercontrol has an array of textboxes called Text1(0) and Text1(1)
Option Explicit

Public Property Get TB(ByVal Index As Integer) As TextBox
   Set TB = Text1(Index)
End Property
'===========

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
Author
30 Jan 2006 3:36 PM
Ken Halter
"Jud Mel" <i***@cube18.com> wrote in message
news:OxCYpzQJGHA.3944@tk2msftngp13.phx.gbl...
> Well, I cant find a way to get to the control since the
> LET\GET functions do not relate to arrays(indexes).

You add the code to support the Index parameter...

> Here is the whole pic, so: When I use the control on a
> dataRepeater, all the repeated controls function as one control (clicking
> the checkBox on the control) and i can not seem to control each one by
> itself. I need to create a user control such
> as this one for example:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconUsingDataRepeaterControl.asp
> but 1 that has either a dynamic control array or a constant one.
>
> How do you address a control through its index?
>
> Hope U understand my needs.
>
> Thanx..

'===========Form Code
Option Explicit

Private Sub Command1_Click()
   UserControl11.TB(0).Text = "This is Text1(0)"
   UserControl11.TB(1).Text = "This is Text1(1)"
End Sub
'===========UserControl Code
'This usercontrol has an array of textboxes called Text1(0) and Text1(1)
Option Explicit

Public Property Get TB(ByVal Index As Integer) As TextBox
   Set TB = Text1(Index)
End Property
'===========

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
Author
31 Jan 2006 8:45 PM
Jud Mel
Thanx but This i already know.

I managed the problem in another way but a bew problem has come up:

Here are the main points of the code:

'In Declarations:
Public Function LoadControl(oForm As Object, _
CtlType As String, CtlName As String) As Object

Dim oCtl As Object

    On Error Resume Next

    If IsObject(oForm.Controls) Then
        Set oCtl = oForm.Controls.Add(CtlType, CtlName)
        If Not oCtl Is Nothing Then Set LoadControl = oCtl

    End If

End Function

Private ctlMyTestControl As VBControlExtender

'In Sub

If Not ctlMyTestControl Is Nothing Then
                ctlMyTestControl.Top = 1000 * i
                 ctlMyTestControl.Left = 100
                ctlMyTestControl.Visible = True
                End If


This works fine, so each time i call an SQL statement i just loop over the
recordcount and display as may controls as i need.

THE thing is I can not get to the controls contained on the UserControl so I
can get to display the recordset on it.

Basically I am trying to display a menu list for a restaurant so each show
of the control will display the name of the course, the price and the units
ordered.

How do I get into these controls on the userControl???

The name of the control is ctlProducts.

I made an OCX and loaded it into the project, i tried defining it in another
way:

Dim aaa As ctlProducts

Set aaa = LoadControl _
               (Me, "VB.ctlProducts", "aaa" & i)

it does not work, i can not get into the textBox on the control.


WHAT DO I DO?

Thanx boys.
Show quoteHide quote
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:uI$urLbJGHA.2708@tk2msftngp13.phx.gbl...
> "Jud Mel" <i***@cube18.com> wrote in message
> news:OxCYpzQJGHA.3944@tk2msftngp13.phx.gbl...
>> Well, I cant find a way to get to the control since the
>> LET\GET functions do not relate to arrays(indexes).
>
> You add the code to support the Index parameter...
>
>> Here is the whole pic, so: When I use the control on a
>> dataRepeater, all the repeated controls function as one control (clicking
>> the checkBox on the control) and i can not seem to control each one by
>> itself. I need to create a user control such
>> as this one for example:
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconUsingDataRepeaterControl.asp
>> but 1 that has either a dynamic control array or a constant one.
>>
>> How do you address a control through its index?
>>
>> Hope U understand my needs.
>>
>> Thanx..
>
> '===========Form Code
> Option Explicit
>
> Private Sub Command1_Click()
>   UserControl11.TB(0).Text = "This is Text1(0)"
>   UserControl11.TB(1).Text = "This is Text1(1)"
> End Sub
> '===========UserControl Code
> 'This usercontrol has an array of textboxes called Text1(0) and Text1(1)
> Option Explicit
>
> Public Property Get TB(ByVal Index As Integer) As TextBox
>   Set TB = Text1(Index)
> End Property
> '===========
>
> --
> Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
> DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
> Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
>
Author
31 Jan 2006 8:45 PM
Jud Mel
Thanx but This i already know.

I managed the problem in another way but a bew problem has come up:

Here are the main points of the code:

'In Declarations:
Public Function LoadControl(oForm As Object, _
CtlType As String, CtlName As String) As Object

Dim oCtl As Object

    On Error Resume Next

    If IsObject(oForm.Controls) Then
        Set oCtl = oForm.Controls.Add(CtlType, CtlName)
        If Not oCtl Is Nothing Then Set LoadControl = oCtl

    End If

End Function

Private ctlMyTestControl As VBControlExtender

'In Sub

If Not ctlMyTestControl Is Nothing Then
                ctlMyTestControl.Top = 1000 * i
                 ctlMyTestControl.Left = 100
                ctlMyTestControl.Visible = True
                End If


This works fine, so each time i call an SQL statement i just loop over the
recordcount and display as may controls as i need.

THE thing is I can not get to the controls contained on the UserControl so I
can get to display the recordset on it.

Basically I am trying to display a menu list for a restaurant so each show
of the control will display the name of the course, the price and the units
ordered.

How do I get into these controls on the userControl???

The name of the control is ctlProducts.

I made an OCX and loaded it into the project, i tried defining it in another
way:

Dim aaa As ctlProducts

Set aaa = LoadControl _
               (Me, "VB.ctlProducts", "aaa" & i)

it does not work, i can not get into the textBox on the control.


WHAT DO I DO?

Thanx boys.
Show quoteHide quote
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:uI$urLbJGHA.2708@tk2msftngp13.phx.gbl...
> "Jud Mel" <i***@cube18.com> wrote in message
> news:OxCYpzQJGHA.3944@tk2msftngp13.phx.gbl...
>> Well, I cant find a way to get to the control since the
>> LET\GET functions do not relate to arrays(indexes).
>
> You add the code to support the Index parameter...
>
>> Here is the whole pic, so: When I use the control on a
>> dataRepeater, all the repeated controls function as one control (clicking
>> the checkBox on the control) and i can not seem to control each one by
>> itself. I need to create a user control such
>> as this one for example:
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconUsingDataRepeaterControl.asp
>> but 1 that has either a dynamic control array or a constant one.
>>
>> How do you address a control through its index?
>>
>> Hope U understand my needs.
>>
>> Thanx..
>
> '===========Form Code
> Option Explicit
>
> Private Sub Command1_Click()
>   UserControl11.TB(0).Text = "This is Text1(0)"
>   UserControl11.TB(1).Text = "This is Text1(1)"
> End Sub
> '===========UserControl Code
> 'This usercontrol has an array of textboxes called Text1(0) and Text1(1)
> Option Explicit
>
> Public Property Get TB(ByVal Index As Integer) As TextBox
>   Set TB = Text1(Index)
> End Property
> '===========
>
> --
> Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
> DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
> Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
>
Author
31 Jan 2006 9:17 PM
Ken Halter
"Jud Mel" <i***@cube18.com> wrote in message
news:%234myybqJGHA.1124@TK2MSFTNGP10.phx.gbl...
> Thanx but This i already know.
>
> I managed the problem in another way but a bew problem has come up:
>

Code to "fix" your problem is in the other group(s) you posted to.

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
Author
31 Jan 2006 9:17 PM
Ken Halter
"Jud Mel" <i***@cube18.com> wrote in message
news:%234myybqJGHA.1124@TK2MSFTNGP10.phx.gbl...
> Thanx but This i already know.
>
> I managed the problem in another way but a bew problem has come up:
>

Code to "fix" your problem is in the other group(s) you posted to.

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
Author
30 Jan 2006 4:31 PM
Mike D Sutton
> Well, I cant find a way to get to the control since the
> LET\GET functions do not relate to arrays(indexes).
>
> Here is the whole pic, so: When I use the control on a
> dataRepeater, all the repeated controls function as one control (clicking
> the checkBox on the control) and i can not seem to control each one by
> itself. I need to create a user control such
> as this one for example:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconUsingDataRepeaterControl.asp
> but 1 that has either a dynamic control array or a constant one.
>
> How do you address a control through its index?

As Ken showed it is possible to access the internal controls, however IMO
this is pretty bad practice since it breaks encapsulation - The usercontrol
should be a 'black box' rather than directly accessing sub controls within
it.  In the example of the data repeater on the MSDN, there should be an
object for each person the control needs to display and the usercontrol
should refresh the appropriate sub-controls as required.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
30 Jan 2006 4:31 PM
Mike D Sutton
> Well, I cant find a way to get to the control since the
> LET\GET functions do not relate to arrays(indexes).
>
> Here is the whole pic, so: When I use the control on a
> dataRepeater, all the repeated controls function as one control (clicking
> the checkBox on the control) and i can not seem to control each one by
> itself. I need to create a user control such
> as this one for example:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconUsingDataRepeaterControl.asp
> but 1 that has either a dynamic control array or a constant one.
>
> How do you address a control through its index?

As Ken showed it is possible to access the internal controls, however IMO
this is pretty bad practice since it breaks encapsulation - The usercontrol
should be a 'black box' rather than directly accessing sub controls within
it.  In the example of the data repeater on the MSDN, there should be an
object for each person the control needs to display and the usercontrol
should refresh the appropriate sub-controls as required.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
29 Jan 2006 6:20 PM
Dmitriy Antonov
"Jud Mel" <i***@cube18.com> wrote in message
news:uwQaMaPJGHA.1728@TK2MSFTNGP09.phx.gbl...
> Hello,
>
> I am trying to create a user control containing a control array, it does
> not seem to work.
> Does anyone know how to do it?
>
> Thanx.
>
> Notice Yehuda Udi Melamed CEO, Cube18 Food Chain Franchise - Israel (
> ?2-6245412 È ?54-7490548 * c**@cube18.com www.Cube18.com
>

What doesn't work? It should work exactly the same way as it works on forms.

Dmitriy.
Author
29 Jan 2006 6:20 PM
Dmitriy Antonov
"Jud Mel" <i***@cube18.com> wrote in message
news:uwQaMaPJGHA.1728@TK2MSFTNGP09.phx.gbl...
> Hello,
>
> I am trying to create a user control containing a control array, it does
> not seem to work.
> Does anyone know how to do it?
>
> Thanx.
>
> Notice Yehuda Udi Melamed CEO, Cube18 Food Chain Franchise - Israel (
> ?2-6245412 È ?54-7490548 * c**@cube18.com www.Cube18.com
>

What doesn't work? It should work exactly the same way as it works on forms.

Dmitriy.