Solved

CType(Page.FindControl Windows equivalent

Posted on 2014-11-07
3
114 Views
Last Modified: 2014-11-10
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
0
Comment
Question by:takwirirar
3 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40428396
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.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 40428716
An example...
    Dim matches() As Control
    For i As Integer = 1 To 12
        matches = Me.Controls.Find("Label" & i, True)
        If matches.Length > 0 AndAlso TypeOf matches(0) Is Label Then
            DirectCast(matches(0), Label).Text = Label14.Text
        End If
    Next

Open in new window

0
 
LVL 40
ID: 40430949
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now