473,698 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing Window Components in C# using Literal names

I have a screen which has as number of textboxes on a screen which I wish to
initialise using a loop. The textboxes are named textBox1, textBox2 etc. I
hoped I hoped that I could address the component as I could in Java, VB6 or
JavaScript in the folllowing manner :

for (int x = 1; x < max;x++)
{
Form1.("textBox " + x.ToString()).T ext = getDetails(x);
}

where getDetails(x) returns the appropriate Text. However I have been
unable to find any syntax which will allow me to do this.

Any Ideas?


--
John Richards
Nov 17 '05 #1
2 1390
Hi,

AFAIK there isn’t any procedure for this as straightforward as in your
example.

You could use any of these instead:
1. Cycle thru the Forms.Controls collection, and check whether the current
item is a text box. If it is, then perform whatever is requried.
2. Use reflection - determine the required name, and use reflection to fetch
the control from the forms object.
3. Maintain an internal hashtable, in which you would add all the required
TextBox controls.

Let me know if you need more assistance.

HTH,
Rakesh Rajan

"Bluelace" wrote:
I have a screen which has as number of textboxes on a screen which I wish to
initialise using a loop. The textboxes are named textBox1, textBox2 etc. I
hoped I hoped that I could address the component as I could in Java, VB6 or
JavaScript in the folllowing manner :

for (int x = 1; x < max;x++)
{
Form1.("textBox " + x.ToString()).T ext = getDetails(x);
}

where getDetails(x) returns the appropriate Text. However I have been
unable to find any syntax which will allow me to do this.

Any Ideas?


--
John Richards

Nov 17 '05 #2
Hi,

AFAIK there isn’t any procedure for this as straightforward as in your
example.

You could use any of these instead:
1. Cycle thru the Forms.Controls collection, and check whether the current
item is a text box. If it is, then perform whatever is requried.
2. Use reflection - determine the required name, and use reflection to fetch
the control from the forms object.
3. Maintain an internal hashtable, in which you would add all the required
TextBox controls.

Let me know if you need more assistance.

HTH,
Rakesh Rajan

"Bluelace" wrote:
I have a screen which has as number of textboxes on a screen which I wish to
initialise using a loop. The textboxes are named textBox1, textBox2 etc. I
hoped I hoped that I could address the component as I could in Java, VB6 or
JavaScript in the folllowing manner :

for (int x = 1; x < max;x++)
{
Form1.("textBox " + x.ToString()).T ext = getDetails(x);
}

where getDetails(x) returns the appropriate Text. However I have been
unable to find any syntax which will allow me to do this.

Any Ideas?


--
John Richards

Nov 17 '05 #3

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

Similar topics

6
2742
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 called "form1", and I have selects called "PORTA", "PORTB" ... etc...
0
270
by: Bluelace | last post by:
I have a screen which has as number of textboxes on a screen which I wish to initialise using a loop. The textboxes are named textBox1, textBox2 etc. I hoped I hoped that I could address the component as I could in Java, VB6 or JavaScript in the folllowing manner : for (int x = 1; x < max;x++) { Form1.("textBox" + x.ToString()).Text = getDetails(x); }
1
11574
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all out). Therefore, here goes my simple "web dialog box with parent event handler fireing" solution. ...
2
947
by: JoshZ | last post by:
Is it possible if i have class x { object a1; object b2; object c3; string names = {"a1", "b2", "c3"}; } to iterate through the class members via Reflection or some other sort of the current class, not just an instance of the class and acess these members and manipulate their properties using their literal names i.e.
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
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
9170
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
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7740
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...
0
5862
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
4372
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
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.