473,396 Members | 1,832 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,396 software developers and data experts.

Access to Controls created by code

I have created various controls by code and added them to a form.

I need for some of them (TextBox) to modify the value.

I use the folowing code to obtain the TextBox wich name is given by sName.

But Me.Controls does not contains my TextBoxes but only the controls
implemented by hand.
This is also confirmed by the spy window.

Thanks for the help.
Dim ctl As Control

For Each ctl In Me.Controls

If TypeOf ctl Is TextBox Then

If ctl.Name = sName Then

Return ctl.Handle

End If

End If

Next
--
Bernard Bourée
be*****@bouree.net
Nov 21 '05 #1
2 1078
Bernard,

Probably is it because you have added your control in another
controlcollection by instance a panel.

Than you can do using your own method

\\\
Dim ctl As Control
For Each ctl In Panel1.Controls
If TypeOf ctl Is TextBox Then
If ctl.Name = sName Then
Return ctl.Handle
End If
End If
Next
///

I advice you however when you dynamicly create controls to set the reference
of those in a kind of array, when you want to do it like this, that you need
to find them by name, than the hashtable can be very effective.

http://msdn.microsoft.com/library/de...classtopic.asp

However this is not the only solution, I use often simple arrays of
controls.

I hope this helps?

Cor
Nov 21 '05 #2
"Bernard Bourée" <be*****@bouree.net> schrieb:
I have created various controls by code and added them to a form.

I need for some of them (TextBox) to modify the value.

I use the folowing code to obtain the TextBox wich name is given by
sName.

But Me.Controls does not contains my TextBoxes but only the controls
implemented by hand.
This is also confirmed by the spy window.


If you added your controls to the form's 'Controls' collection, this
collection will contain the textboxes too. Make sure you set the controls'
'Name' property to the name so the comparison with the name will be
successful for the controls.

Additional information:

Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #3

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

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
5
by: Andrei Pociu | last post by:
Inside a method some controls are created at runtime. I added an event handler to one of these controls: tracker.Scroll += new System.EventHandler(this.tracker_Scroll); So in the event handler...
2
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2...
5
by: jqpdev | last post by:
Hello all... I'm coming from a Borland Delphi background. Delphi has a specific component called a Data Module. In the designer the Data Module behaves like a windows form. A developer can...
7
by: Lau Lei Cheong | last post by:
Hello, I'm using javascript's insertAdjacentHtml() to insert images to the webform at runtime. This runs fine(image successfully displayed at the browser) but when I tried to access the...
2
by: c676228 | last post by:
Hi, I created a group of user controls in an aspx form. which is as follow: <body> <form id="Form1" method="post" runat="server"> <SUBWAY:PEOPLEINFO id="Peopleinfo0" runat="server"...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
7
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using...
6
by: Wesley Peace | last post by:
I hate to cross post, but I've gotten no answer yet on a problem I'm having with visual studio 2008. I've created a series of forms with controls to access a Access database tables. The...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.