473,657 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find a control on a form of a specific name

I have a form that might (or might not) have a textbox on it named
something particular - how can I find if the form has the control, and
if it does what the text of the control has? This form has textboxes
that are created on the fly, and when the OK is clicked I need to figure
out which ones are on the screen and what the text is in each to do
other stuff.

So, kind of like:

dim xstr as string
xstr=me.findcon trol("tText").t ostring

Thanks.

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Nov 8 '06 #1
3 1686
Try this. It's not terribly elegant, but I think
it will get the job done.
------------------
'call with the name of the control you're looking for
If ControlIsThere( "MyBigGiantText Box") Then...

'You need this to be available in both the
'function and the recursive routine that
'it calls, so you have something to stop
'the recursion. I'd make it a form-level
'variable.
Dim FoundControl as Boolean

Private Function ControlIsThere( controlName as String) as Boolean
'Set this to false.
FoundControl = False
'Call the recursive routine with the form.
ControlExists(M e)
'Return the result.
Return FoundControl
End Function

'This will recurse, so it gets all the controls on the form.
'This way, if you have panels, for example, it will
' touch the controls inside those containers.
Private Sub ControlExists(B yVal ctrlContainer As Control)
For Each ctrl As Control In ctrlContainer.C ontrols
'Debug.Print(ct rl.Name.ToStrin g)
If ctrl.Name = "MyBigGiantText Box" Then
FoundControl = True
Exit For
End If
'if control has children, call this function recursively
If ctrl.HasChildre n Then
ControlExists(c trl)
End If
Next
End Sub

Robin S.

"Darin" <darin_nospam@n ospameverwrote in message
news:e6******** ******@TK2MSFTN GP02.phx.gbl...
>I have a form that might (or might not) have a textbox on it named
something particular - how can I find if the form has the control, and
if it does what the text of the control has? This form has textboxes
that are created on the fly, and when the OK is clicked I need to figure
out which ones are on the screen and what the text is in each to do
other stuff.

So, kind of like:

dim xstr as string
xstr=me.findcon trol("tText").t ostring

Thanks.

Darin

*** Sent via Developersdex http://www.developersdex.com ***

Nov 8 '06 #2
You know, I'm not sure if this will pick up controls that are contains
within control containers on a form, but what's wrong with this:

Public Function ContainsControl ("ControlYourLo okingFor" as string) as
Control
for each ctl as control in me.controls
if string.Compare( ctl.name, "ControlYourLoo kingFor", True) then
return ctl
end if
next
end function

if not ctl is nothing then
' get the text of the control and do something with it
end if

HTH
Steve

"Darin" <darin_nospam@n ospameverwrote in message
news:e6******** ******@TK2MSFTN GP02.phx.gbl...
>I have a form that might (or might not) have a textbox on it named
something particular - how can I find if the form has the control, and
if it does what the text of the control has? This form has textboxes
that are created on the fly, and when the OK is clicked I need to figure
out which ones are on the screen and what the text is in each to do
other stuff.

So, kind of like:

dim xstr as string
xstr=me.findcon trol("tText").t ostring

Thanks.

Darin

*** Sent via Developersdex http://www.developersdex.com ***

Nov 8 '06 #3
"Darin" <darin_nospam@n ospameverschrie b:
>I have a form that might (or might not) have a textbox on it named
something particular - how can I find if the form has the control, and
if it does what the text of the control has? This form has textboxes
that are created on the fly, and when the OK is clicked I need to figure
out which ones are on the screen and what the text is in each to do
other stuff.
If you are using .NET 2.0 and you know the container control containing the
control you can use '<container control>.Contro ls("TextBox22") ' to obtain a
reference to the control.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1593
by: Yasutaka Ito | last post by:
Hi, Is there a way to find to which control the current control is docked against? For example, let's say I have panel1 and panel2 docked to left within a form. The panel1 is the first one on the left and the panel2 is the second one docked against panel1. I want to be able to find out to which control/form the specified panel.
3
4169
by: Not Me | last post by:
Hi, Just trying to get my head around tab controls, is there anywhere which would describe the structure of how they work? I seem to be ok so far, being able to check which page I'm on etc... but I'm at a loss when trying to access controls inside the tabs. If I try to access the form directly (!...etc.) I get an error that the form can't be found. I'm not sure how I can use parent/child relationships to get at the (sub)forms which...
6
11276
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header" Src="WebControls/Header.ascx" %> The web user control contains the following server controls
10
5304
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a certain control by id, but I want to find all controls of a certain type (DropDownList in this case). Is there an easier way than to get a control count of the page, loop through all controls on that page, examine their type and, if they're a...
4
2509
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once I have exposed a public property containing the value of a textbox in a user control..how do I grab this from the calling page? I cant think of the syntax, since my page doesnt know the contents of the class (and therefore, the public...
5
2809
by: Richard Brown | last post by:
Ok, I've been looking through the .NET SDK docs and stuff. I'm wondering if you can provide a control extender that does generic validation or functionality just by dropping it on the form. For instance, using the IExtenderProvider interface, you can specify properties, but there is nothing documented about linking into a control's events. For instance, in my application, there are specific formatting, functionality and validation for...
5
1516
by: Paul Bromley | last post by:
Can someone give me a very simple example on how to do this? As an example I have a commaned button in a user control. Once this user control is placed on a form I want to be able to respond in the form to the button click on the user control. In a simple example - how do I do this. Do I need to use Delegates, and if so can you give a very simple example. Many thanks Paul Bromley
11
2618
by: -D- | last post by:
How can I turn the visibility of the xml control on or off? <%@ Control Language="c#" AutoEventWireup="false" Codebehind="TopNavBar.ascx.cs" Inherits="compass.user_controls.TopNavBar" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> <table cellSpacing="0" cellPadding="0" border="0"> <colgroup span="1" align="left" width="50%"> </colgroup> <colgroup span="1" align="right" width="50%"> </colgroup>
5
4538
by: YaoBao | last post by:
Is any ColdFusion script I can put on my webpage that will create a search bar so people can type keywords to match it on the current page in my website? It will be exactly like the finder search bar that comes with your browser window, IE; click edit, then find on this page, which brings up the search box. I know that JavaScript can do this. I tried to insert JavaScript to my .cfm page. It doesn't work. Any help will be appreciated. Here...
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.