short question

  • Thread starter Thread starter Dinio
  • Start date Start date
D

Dinio

hi to all.
Anybody knows how can i create an array of textboxes..

something like:
protected TextBox[] mygroup1

Thanks
Dinio Aynama
 
Dinio,

first of all, you have to decide how many textBoxes the array will contain
(if this is unknown, use an ArrayList or other collection)

protectd TextBox[] mygroup1 = new TextBox[10];

after that, you have to initialize (instanciate) each textbox:

for (int i=0;i<mygroup1.Length;i++)
{
mygroup1 = new TextBox();
}

you can also initialize the array and dimension at the same time:

protected TextBox[] mygroup1 = new TextBox[] {new TextBox(), new TextBox(),
.... };

thats not a good idea since you probably want to assign values to the
various TextBox propeties of each TextBox object (as you can do in the for
loop).

Picho
 
Thanks Picho, but i have a little dude...

My class (derives from webcontrol) have this constructor

public example()
{
for(int i=0;int<num;i++)
{
//MyGroup is an array of TextBoxes Property inside
//the class
this.MyGroup=new TextBox();
this.Controls.add(this.MyGroup);
}
}
My question is very easy... I would like to know hoy can i
manage the variable num in the loop... Cause i have
another class that returns to me a number of elements
depending of a query in a database... I would like to show
as many TextBoxes as results in my query...

Thanks Picho.
Regards.
Josema.
-----Original Message-----
Dinio,

first of all, you have to decide how many textBoxes the array will contain
(if this is unknown, use an ArrayList or other collection)

protectd TextBox[] mygroup1 = new TextBox[10];

after that, you have to initialize (instanciate) each textbox:

for (int i=0;i<mygroup1.Length;i++)
{
mygroup1 = new TextBox();
}

you can also initialize the array and dimension at the same time:

protected TextBox[] mygroup1 = new TextBox[] {new TextBox (), new TextBox(),
.... };

thats not a good idea since you probably want to assign values to the
various TextBox propeties of each TextBox object (as you can do in the for
loop).

Picho

hi to all.
Anybody knows how can i create an array of textboxes..

something like:
protected TextBox[] mygroup1

Thanks
Dinio Aynama


.
 
Josema said:
Thanks Picho, but i have a little dude...

My class (derives from webcontrol) have this constructor

public example()
{
for(int i=0;int<num;i++)
{
//MyGroup is an array of TextBoxes Property inside
//the class
this.MyGroup=new TextBox();
this.Controls.add(this.MyGroup);
}
}
My question is very easy... I would like to know hoy can i
manage the variable num in the loop... Cause i have
another class that returns to me a number of elements


So just have:

MyGroup = new TextBox[num];

at the start of the constructor instead.
 
Back
Top