Solved

CType(Page.FindControl Windows equivalent

Posted on 2014-11-07
3
118 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 63

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 86

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

737 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