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

control help

I have 10 textboxes on my page, textbox1 - textbox10. Rather than modify
them individually, I would like to modify them with a variable something
like this:

for (int i = 0; i <= 10; i++)
{
textbox[i].text = "some text";
}

Is this possible? Would I need to create some kind of control array?

Thanks,
Dave
Nov 15 '05 #1
2 1601
You could either not use the form designer to create them, by creating them
in your constructor like this:

public Form() {
InitializeComponent();
TextBox[] txts = new TextBox[10];
for (int i = 0; i < 10; i++) {
TextBox t = new TextBox();
t.Location =
t.Size =
t.Text =
txts.Add(t);
Controls.Add(t);
}
}

or you could assign them afterwards manually

TextBox[] txts = new TextBox[10];
txts[0] = textBox1; txts[1] = textBox2; etc;

Chris

"Dave Petersen" <da*******************@carlson.com> wrote in message
news:#V**************@TK2MSFTNGP10.phx.gbl...
I have 10 textboxes on my page, textbox1 - textbox10. Rather than modify
them individually, I would like to modify them with a variable something
like this:

for (int i = 0; i <= 10; i++)
{
textbox[i].text = "some text";
}

Is this possible? Would I need to create some kind of control array?

Thanks,
Dave

Nov 15 '05 #2
Chris,
thanks for the info. I ended up doing this:

TextBox[] txts = new TextBox[10];
txts[0] = TextBox1;
txts[1] = TextBox2;
....

for (int i = 0; i <= 9; i++)
{
txts[i].Text = "Control " + Convert.ToString(i + 1);
}

It worked great!
Dave

"Chris Capel" <ch***@nowhere.com> wrote in message
news:#G**************@tk2msftngp13.phx.gbl...
You could either not use the form designer to create them, by creating them in your constructor like this:

public Form() {
InitializeComponent();
TextBox[] txts = new TextBox[10];
for (int i = 0; i < 10; i++) {
TextBox t = new TextBox();
t.Location =
t.Size =
t.Text =
txts.Add(t);
Controls.Add(t);
}
}

or you could assign them afterwards manually

TextBox[] txts = new TextBox[10];
txts[0] = textBox1; txts[1] = textBox2; etc;

Chris

"Dave Petersen" <da*******************@carlson.com> wrote in message
news:#V**************@TK2MSFTNGP10.phx.gbl...
I have 10 textboxes on my page, textbox1 - textbox10. Rather than modify them individually, I would like to modify them with a variable something
like this:

for (int i = 0; i <= 10; i++)
{
textbox[i].text = "some text";
}

Is this possible? Would I need to create some kind of control array?

Thanks,
Dave


Nov 15 '05 #3

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

Similar topics

4
by: Scott C. Reynolds | last post by:
Hi. I have created a templated control, and I want to know how i can set it up so that the projects consuming it will have all the same intellisense benefits of using any other server control. ...
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
3
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate>...
4
by: ray well | last post by:
in my app i need to make a RichTextbox control transparent. i need it to be a like a pane of glass lying on a sheet of paper, where u can see everything on the sheet of paper not covered by text...
11
by: -D- | last post by:
How can I turn the visibility of the xml control on or off? <%@ Control Language="c#" AutoEventWireup="false" Codebehind="TopNavBar.ascx.cs" Inherits="compass.user_controls.TopNavBar"...
15
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
9
by: Nathan Sokalski | last post by:
I am using ASP.NET 2.0's ImageMap Control to create 2 imagemaps, one directly below the other. When I do this a thin blank space appears between them. After several days of frustration I realized...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
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.