Solved

CType(Page.FindControl Windows equivalent

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

22 Experts available now in Live!

Get 1:1 Help Now