473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Accessing a control if its name is in a string variable

I have the name of a control in a string variable and I want to change one
of the controls properties. Right now I recursively scan all the controls
on the form until I get one whose name matches the name in my string
variable, then I know I have the correct control and can proceed to change
the property.
However all that searching seems like overkill. Does anyone know of a way
to directly access the control if it's name is in a string variable?
Something like an indirect access...
Thanks for any advice...
Jul 5 '07 #1
9 1897
"JohnR" <Jo******@hotmail.com>'s wild thoughts were released
on Thu, 05 Jul 2007 05:02:56 GMT bearing the following
fruit:
>I have the name of a control in a string variable and I want to change one
of the controls properties. Right now I recursively scan all the controls
on the form until I get one whose name matches the name in my string
variable, then I know I have the correct control and can proceed to change
the property.
However all that searching seems like overkill. Does anyone know of a way
to directly access the control if it's name is in a string variable?
Something like an indirect access...
Thanks for any advice...

Me.Controls("TextEdit1").Text = "Hello"
--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde
Jul 5 '07 #2
JohnR wrote:
I have the name of a control in a string variable and I want to change one
of the controls properties. Right now I recursively scan all the controls
on the form until I get one whose name matches the name in my string
variable, then I know I have the correct control and can proceed to change
the property.
However all that searching seems like overkill. Does anyone know of a way
to directly access the control if it's name is in a string variable?
Something like an indirect access...
Thanks for any advice...

try Controls.Find [http://msdn2.microsoft.com/en-us/library/ms404295.aspx]
Althought the MSDN sample is about keyed collectios, in the begining of
the page is shown how to focus on control specified by it's name.

Regards,
Petar Atansov
http://a-wake.net
Jul 5 '07 #3
Jan,

Cylix is in my opinion doing it correct recursively, I assume he wants to
find the controls on a panel to.

Your me.controls shows in my idea only the controls on the top of the form.

Although I did not check it, the Find is also to find in a collection, not
to find a child in a collection.

However I am not 100% sure about the last.

Cor

"Jan Hyde (VB MVP)" <St***********@REMOVE.ME.uboot.comschreef in bericht
news:a0********************************@4ax.com...
"JohnR" <Jo******@hotmail.com>'s wild thoughts were released
on Thu, 05 Jul 2007 05:02:56 GMT bearing the following
fruit:
>>I have the name of a control in a string variable and I want to change one
of the controls properties. Right now I recursively scan all the controls
on the form until I get one whose name matches the name in my string
variable, then I know I have the correct control and can proceed to change
the property.
However all that searching seems like overkill. Does anyone know of a way
to directly access the control if it's name is in a string variable?
Something like an indirect access...
Thanks for any advice...


Me.Controls("TextEdit1").Text = "Hello"
--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde

Jul 5 '07 #4
On Jul 5, 6:52 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
Jan,

Cylix is in my opinion doing it correct recursively, I assume he wants to
find the controls on a panel to.

Your me.controls shows in my idea only the controls on the top of the form.

Although I did not check it, the Find is also to find in a collection, not
to find a child in a collection.

However I am not 100% sure about the last.

Cor

"Jan Hyde (VB MVP)" <StellaDrin...@REMOVE.ME.uboot.comschreef in berichtnews:a0********************************@4ax .com...
"JohnR" <JohnR...@hotmail.com>'s wild thoughts were released
on Thu, 05 Jul 2007 05:02:56 GMT bearing the following
fruit:
>I have the name of a control in a string variable and I want to change one
of the controls properties. Right now I recursively scan all the controls
on the form until I get one whose name matches the name in my string
variable, then I know I have the correct control and can proceed to change
the property.
However all that searching seems like overkill. Does anyone know of a way
to directly access the control if it's name is in a string variable?
Something like an indirect access...
Thanks for any advice...
Me.Controls("TextEdit1").Text = "Hello"
--
Jan Hyde
https://mvp.support.microsoft.com/profile/Jan.Hyde
Although I did not check it, the Find is also to find in a collection, not
to find a child in a collection.
Controls.Find has a searchAllChildren bool parameter that you can use
to specify a recursive search.

Thanks,

Seth Rowe

Jul 5 '07 #5
Hi all,

Thanks for the great replies. Looks like Control.find will do what I want,
but that method was introduced in .NET 2.0 and we have not upgraded yet.
So, I'll continue doing it manually (at least it works), until we upgrade
later this year.
Thanks again...

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
On Jul 5, 6:52 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
>Jan,

Cylix is in my opinion doing it correct recursively, I assume he wants to
find the controls on a panel to.

Your me.controls shows in my idea only the controls on the top of the
form.

Although I did not check it, the Find is also to find in a collection,
not
to find a child in a collection.

However I am not 100% sure about the last.

Cor

"Jan Hyde (VB MVP)" <StellaDrin...@REMOVE.ME.uboot.comschreef in
berichtnews:a0********************************@4a x.com...
"JohnR" <JohnR...@hotmail.com>'s wild thoughts were released
on Thu, 05 Jul 2007 05:02:56 GMT bearing the following
fruit:
>>I have the name of a control in a string variable and I want to change
one
of the controls properties. Right now I recursively scan all the
controls
on the form until I get one whose name matches the name in my string
variable, then I know I have the correct control and can proceed to
change
the property.
However all that searching seems like overkill. Does anyone know of a
way
to directly access the control if it's name is in a string variable?
Something like an indirect access...
Thanks for any advice...
Me.Controls("TextEdit1").Text = "Hello"
--
Jan Hyde
>https://mvp.support.microsoft.com/profile/Jan.Hyde

>Although I did not check it, the Find is also to find in a collection,
not
to find a child in a collection.

Controls.Find has a searchAllChildren bool parameter that you can use
to specify a recursive search.

Thanks,

Seth Rowe

Jul 5 '07 #6
Seth

I had the plan to check it when I was home, but now you did it for me.

Thanks

Cor

"rowe_newsgroups" <ro********@yahoo.comschreef in bericht
news:11**********************@g4g2000hsf.googlegro ups.com...
On Jul 5, 6:52 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
>Jan,

Cylix is in my opinion doing it correct recursively, I assume he wants to
find the controls on a panel to.

Your me.controls shows in my idea only the controls on the top of the
form.

Although I did not check it, the Find is also to find in a collection,
not
to find a child in a collection.

However I am not 100% sure about the last.

Cor

"Jan Hyde (VB MVP)" <StellaDrin...@REMOVE.ME.uboot.comschreef in
berichtnews:a0********************************@4a x.com...
"JohnR" <JohnR...@hotmail.com>'s wild thoughts were released
on Thu, 05 Jul 2007 05:02:56 GMT bearing the following
fruit:
>>I have the name of a control in a string variable and I want to change
one
of the controls properties. Right now I recursively scan all the
controls
on the form until I get one whose name matches the name in my string
variable, then I know I have the correct control and can proceed to
change
the property.
However all that searching seems like overkill. Does anyone know of a
way
to directly access the control if it's name is in a string variable?
Something like an indirect access...
Thanks for any advice...
Me.Controls("TextEdit1").Text = "Hello"
--
Jan Hyde
>https://mvp.support.microsoft.com/profile/Jan.Hyde

>Although I did not check it, the Find is also to find in a collection,
not
to find a child in a collection.

Controls.Find has a searchAllChildren bool parameter that you can use
to specify a recursive search.

Thanks,

Seth Rowe

Jul 5 '07 #7
JohnR,

If you need to do this for several controls, then you could scan all the
controls on the form once, adding the control to a hashtable and using the
control's name as the key.

Once all the controls are in the hashtable, you could access them by the
hashtable's key, the name of the control.

But this won't gain you any performance benefit if you just need to access
one control by name one time in your app.

Kerry Moorman
"JohnR" wrote:
Hi all,

Thanks for the great replies. Looks like Control.find will do what I want,
but that method was introduced in .NET 2.0 and we have not upgraded yet.
So, I'll continue doing it manually (at least it works), until we upgrade
later this year.
Thanks again...

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
On Jul 5, 6:52 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
Jan,

Cylix is in my opinion doing it correct recursively, I assume he wants to
find the controls on a panel to.

Your me.controls shows in my idea only the controls on the top of the
form.

Although I did not check it, the Find is also to find in a collection,
not
to find a child in a collection.

However I am not 100% sure about the last.

Cor

"Jan Hyde (VB MVP)" <StellaDrin...@REMOVE.ME.uboot.comschreef in
berichtnews:a0********************************@4ax .com...

"JohnR" <JohnR...@hotmail.com>'s wild thoughts were released
on Thu, 05 Jul 2007 05:02:56 GMT bearing the following
fruit:

I have the name of a control in a string variable and I want to change
one
of the controls properties. Right now I recursively scan all the
controls
on the form until I get one whose name matches the name in my string
variable, then I know I have the correct control and can proceed to
change
the property.
However all that searching seems like overkill. Does anyone know of a
way
to directly access the control if it's name is in a string variable?
Something like an indirect access...
Thanks for any advice...

Me.Controls("TextEdit1").Text = "Hello"
--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde
Although I did not check it, the Find is also to find in a collection,
not
to find a child in a collection.
Controls.Find has a searchAllChildren bool parameter that you can use
to specify a recursive search.

Thanks,

Seth Rowe


Jul 5 '07 #8
Hi Kerry,

Ya know, that's a great idea. That's exactly what I'll do.

Thanks, John

"Kerry Moorman" <Ke**********@discussions.microsoft.comwrote in message
news:2A**********************************@microsof t.com...
JohnR,

If you need to do this for several controls, then you could scan all the
controls on the form once, adding the control to a hashtable and using the
control's name as the key.

Once all the controls are in the hashtable, you could access them by the
hashtable's key, the name of the control.

But this won't gain you any performance benefit if you just need to access
one control by name one time in your app.

Kerry Moorman
"JohnR" wrote:
>Hi all,

Thanks for the great replies. Looks like Control.find will do what I
want,
but that method was introduced in .NET 2.0 and we have not upgraded yet.
So, I'll continue doing it manually (at least it works), until we upgrade
later this year.
Thanks again...

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@g4g2000hsf.googlegr oups.com...
On Jul 5, 6:52 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
Jan,

Cylix is in my opinion doing it correct recursively, I assume he wants
to
find the controls on a panel to.

Your me.controls shows in my idea only the controls on the top of the
form.

Although I did not check it, the Find is also to find in a
collection,
not
to find a child in a collection.

However I am not 100% sure about the last.

Cor

"Jan Hyde (VB MVP)" <StellaDrin...@REMOVE.ME.uboot.comschreef in
berichtnews:a0********************************@4a x.com...

"JohnR" <JohnR...@hotmail.com>'s wild thoughts were released
on Thu, 05 Jul 2007 05:02:56 GMT bearing the following
fruit:

I have the name of a control in a string variable and I want to
change
one
of the controls properties. Right now I recursively scan all the
controls
on the form until I get one whose name matches the name in my string
variable, then I know I have the correct control and can proceed to
change
the property.
However all that searching seems like overkill. Does anyone know of
a
way
to directly access the control if it's name is in a string variable?
Something like an indirect access...
Thanks for any advice...

Me.Controls("TextEdit1").Text = "Hello"
--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde
Although I did not check it, the Find is also to find in a
collection,
not
to find a child in a collection.

Controls.Find has a searchAllChildren bool parameter that you can use
to specify a recursive search.

Thanks,

Seth Rowe



Jul 5 '07 #9
On Jul 5, 3:52 pm, Kerry Moorman
<KerryMoor...@discussions.microsoft.comwrote:
JohnR,

If you need to do this for several controls, then you could scan all the
controls on the form once, adding the control to a hashtable and using the
control's name as the key.

Once all the controls are in the hashtable, you could access them by the
hashtable's key, the name of the control.

But this won't gain you any performance benefit if you just need to access
one control by name one time in your app.

Kerry Moorman

"JohnR" wrote:
Hi all,
Thanks for the great replies. Looks like Control.find will do what I want,
but that method was introduced in .NET 2.0 and we have not upgraded yet.
So, I'll continue doing it manually (at least it works), until we upgrade
later this year.
Thanks again...
"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
On Jul 5, 6:52 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
>Jan,
>Cylix is in my opinion doing it correct recursively, I assume he wants to
>find the controls on a panel to.
>Your me.controls shows in my idea only the controls on the top of the
>form.
>Although I did not check it, the Find is also to find in a collection,
>not
>to find a child in a collection.
>However I am not 100% sure about the last.
>Cor
>"Jan Hyde (VB MVP)" <StellaDrin...@REMOVE.ME.uboot.comschreef in
>berichtnews:a0********************************@4a x.com...
"JohnR" <JohnR...@hotmail.com>'s wild thoughts were released
on Thu, 05 Jul 2007 05:02:56 GMT bearing the following
fruit:
>>I have the name of a control in a string variable and I want to change
>>one
>>of the controls properties. Right now I recursively scan all the
>>controls
>>on the form until I get one whose name matches the name in my string
>>variable, then I know I have the correct control and can proceed to
>>change
>>the property.
>>However all that searching seems like overkill. Does anyone know of a
>>way
>>to directly access the control if it's name is in a string variable?
>>Something like an indirect access...
>>Thanks for any advice...
Me.Controls("TextEdit1").Text = "Hello"
--
Jan Hyde
>https://mvp.support.microsoft.com/profile/Jan.Hyde
>Although I did not check it, the Find is also to find in a collection,
>not
>to find a child in a collection.
Controls.Find has a searchAllChildren bool parameter that you can use
to specify a recursive search.
Thanks,
Seth Rowe
You might also want to subscribe to the form's controladded event and
add any dynamically created controls that were created after your scan
to your hashtable.

Thanks,

Seth Rowe

Jul 6 '07 #10

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

Similar topics

18
by: Joe | last post by:
Hi, I am trying to alter the refresh rate of an online webpage in a webbrowser control using MFC. However the Timer ID is stored in a local variable and I don't know how to access it. Is there a...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
2
by: Matt Smolic | last post by:
02.06.04 I need some help displaying a public variable on a form. The variable is declared and initilazied in a module at startup (and declared Public). I have verified this with a...
3
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different...
5
by: Dan Nash | last post by:
Hi all, I've got a page with a user control on, added via VS. I'm trying to get to a property of the user control (or more precisely, a public var). Here's the code at the top of my aspx...
6
by: David Hearn | last post by:
I have a property in a user control that I am setting: Private strPageName as String Public Property PageName() as String Get Return strPageName End Get Set(byVal Value as String)...
2
by: Vincent | last post by:
I have been trying to find some API routines that will allow me to determine the name of the computer that is accessing a file on a server. I have found the NetFileEnum call (returns the names of...
4
by: John Kotuby | last post by:
Hi all, I am using a Repeater in conjunction with a SQLDatasource and SQL Server. One of the controls in the repeater is a HyperlLink as follows: <asp:HyperLink...
0
by: ansh20 | last post by:
I am adding run time generate controls in array. Now I want to retrieve those controls in other subroutine in same form. But when I am tring to retrieve control it says "Object variable or with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.