473,797 Members | 3,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

quick easy answer for this question

I am kind of new to C sharp; I have a quick question I have multiple
text boxes 12 of them to be exact. What I want to do is fill them with
values that are in a array of integers. The way I am currently doing
this is like this..

input0.Text = Convert.ToStrin g(arr[0]);
input1.Text = Convert.ToStrin g(arr[1]);
input2.Text = Convert.ToStrin g(arr[2]);
input3.Text = Convert.ToStrin g(arr[3]);
input4.Text = Convert.ToStrin g(arr[4]);
input5.Text = Convert.ToStrin g(arr[5]);
input6.Text = Convert.ToStrin g(arr[6]);
input7.Text = Convert.ToStrin g(arr[7]);
input8.Text = Convert.ToStrin g(arr[8]);
input9.Text = Convert.ToStrin g(arr[9]);
input10.Text = Convert.ToStrin g(arr[10]);
input11.Text = Convert.ToStrin g(arr[11]);

What I am looking for is about 3 lines of code; something like this...

for(i = 0; i< arr.Length; i++)
{
input[i].Text = Convert.ToStrin g(arr[i]);
//NOTE: I am using [i] as the subscript for the texboxes
}

I doubt this can be done in C sharp; but any help or ideas will be
appreciated. Also note that I posted the same message on the c-sharp
message board; but it doesn't look like it gets as much traffic as this
group does.

Thanks,
-Jimmie

Feb 10 '06 #1
7 1447
> What I am looking for is about 3 lines of code; something like this...

for(i = 0; i< arr.Length; i++)
{
input[i].Text = Convert.ToStrin g(arr[i]);
//NOTE: I am using [i] as the subscript for the texboxes
}
What youu're talking about doing is using an indexer. In order to do that,
the Controls have to be in an array or a Collection. Of course, you can put
them into one if you wish.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
<ji******@hotma il.com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...I am kind of new to C sharp; I have a quick question I have multiple
text boxes 12 of them to be exact. What I want to do is fill them with
values that are in a array of integers. The way I am currently doing
this is like this..

input0.Text = Convert.ToStrin g(arr[0]);
input1.Text = Convert.ToStrin g(arr[1]);
input2.Text = Convert.ToStrin g(arr[2]);
input3.Text = Convert.ToStrin g(arr[3]);
input4.Text = Convert.ToStrin g(arr[4]);
input5.Text = Convert.ToStrin g(arr[5]);
input6.Text = Convert.ToStrin g(arr[6]);
input7.Text = Convert.ToStrin g(arr[7]);
input8.Text = Convert.ToStrin g(arr[8]);
input9.Text = Convert.ToStrin g(arr[9]);
input10.Text = Convert.ToStrin g(arr[10]);
input11.Text = Convert.ToStrin g(arr[11]);

What I am looking for is about 3 lines of code; something like this...

for(i = 0; i< arr.Length; i++)
{
input[i].Text = Convert.ToStrin g(arr[i]);
//NOTE: I am using [i] as the subscript for the texboxes
}

I doubt this can be done in C sharp; but any help or ideas will be
appreciated. Also note that I posted the same message on the c-sharp
message board; but it doesn't look like it gets as much traffic as this
group does.

Thanks,
-Jimmie

Feb 10 '06 #2
<ji******@hotma il.com> wrote:
I am kind of new to C sharp; I have a quick question I have multiple
text boxes 12 of them to be exact. What I want to do is fill them with
values that are in a array of integers. The way I am currently doing
this is like this..
<snip>
What I am looking for is about 3 lines of code; something like this...

for(i = 0; i< arr.Length; i++)
{
input[i].Text = Convert.ToStrin g(arr[i]);
//NOTE: I am using [i] as the subscript for the texboxes
}

I doubt this can be done in C sharp; but any help or ideas will be
appreciated. Also note that I posted the same message on the c-sharp
message board; but it doesn't look like it gets as much traffic as this
group does.


The best thing to do would be to have an array instead of 12 different
fields. You won't get a lot of designer support for it, but it's not
hard to do manually.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 10 '06 #3
First, you should be using generics instead of an array. See:
http://msdn.microsoft.com/library/de...p_generics.asp

Now, for a WinForm app:

for (int i = 0; i < list.Count; i++)
{
TextBox t = (TextBox)
Controls[string.Format(" TextBox{0}", i)];
t.Text = list[i].ToString();
}

For a WebForm app:
for (int i = 0; i < list.Count; i++)
{
TextBox t = (TextBox)
FindControl(str ing.Format("Tex tBox{0}", i));
t.Text = list[i].ToString();
}

David Barkol
www.neudesic.com

Feb 10 '06 #4
Aight kool so basically search indexer + examples on the net?

-Jimmie

Feb 10 '06 #5
Ahh aight good deal guys, thanks for the info.

-Jimmie

Feb 10 '06 #6
Hi jimi,

You actually can do this in C# with some careful control naming. Below is
some sample code that should help:

//There are 9 text boxes, what this will do is set the text in
each of the
//textboxes to the value of that textboxes index in the
form.control array.
for (int i = 1; i < 9; i++)
{
//this call will find the location of the textbox by name,
so it's important
//to note that my textboxes are named textBox1,textBo x2,etc.
int controlLocation = this.Controls.I ndexOfKey("text Box" +
i.ToString());

//Now we access that control through the form.control array
and change it's text
this.Controls[controlLocation].Text = i.ToString();
}

That should help you out hopefully! If this is what you were looking for
please remember to mark the thread as answered. Thanks!
"ji******@hotma il.com" wrote:
I am kind of new to C sharp; I have a quick question I have multiple
text boxes 12 of them to be exact. What I want to do is fill them with
values that are in a array of integers. The way I am currently doing
this is like this..

input0.Text = Convert.ToStrin g(arr[0]);
input1.Text = Convert.ToStrin g(arr[1]);
input2.Text = Convert.ToStrin g(arr[2]);
input3.Text = Convert.ToStrin g(arr[3]);
input4.Text = Convert.ToStrin g(arr[4]);
input5.Text = Convert.ToStrin g(arr[5]);
input6.Text = Convert.ToStrin g(arr[6]);
input7.Text = Convert.ToStrin g(arr[7]);
input8.Text = Convert.ToStrin g(arr[8]);
input9.Text = Convert.ToStrin g(arr[9]);
input10.Text = Convert.ToStrin g(arr[10]);
input11.Text = Convert.ToStrin g(arr[11]);

What I am looking for is about 3 lines of code; something like this...

for(i = 0; i< arr.Length; i++)
{
input[i].Text = Convert.ToStrin g(arr[i]);
//NOTE: I am using [i] as the subscript for the texboxes
}

I doubt this can be done in C sharp; but any help or ideas will be
appreciated. Also note that I posted the same message on the c-sharp
message board; but it doesn't look like it gets as much traffic as this
group does.

Thanks,
-Jimmie

Feb 10 '06 #7
Not sure on how to mark as answered; but thank you everyone.

-Jimmie

Feb 10 '06 #8

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

Similar topics

0
9685
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
9536
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
10245
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
10021
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
9063
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
7559
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
6802
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
5458
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...
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.