Link to home
Start Free TrialLog in
Avatar of David C
David CFlag for United Kingdom of Great Britain and Northern Ireland

asked on

CType(Page.FindControl Windows equivalent

Hi, is there an equivalent in VB.NET Windows Applications for

CType(Page.FindControl("Label" & i), Label).Text = Label14.Text

variable i will be incrementing

Thanks
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

From Microsoft Documentation:
Searches for controls by their Name property and builds an array of all the controls that match.

'Declaration
Public Function Find ( _
	key As String, _
	searchAllChildren As Boolean _
) As Control()

Open in new window


Parameters
key
    Type: System.String
    The key to locate in the Control.ControlCollection.

searchAllChildren
    Type: System.Boolean
    true to search all child controls; otherwise, false.

Return Value
    Type: System.Windows.Forms.Control()
    An array of type Control containing the matching controls.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Assuming that you know that there is a Label for each value of i, and that Page is a form:

     Page.Controls("Label" & i.ToString).Text = Label14.Text

If the Label is in the same form as the code then:

     Me.Controls("Label" & i.ToString).Text = Label14.Text