Solved

CType(Page.FindControl Windows equivalent

Posted on 2014-11-07
3
115 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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