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

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()).Text = 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 1370
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()).Text = 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()).Text = 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
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...
0
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...
1
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...
2
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...
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:
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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.