Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textbox collection/arraylist 2

Status
Not open for further replies.

tekkerguy

Programmer
Nov 16, 2005
196
0
0
US
is it possible to add textboxes to array list? I've tried, and it adds them ok, but when I go to retrieve them to pull the text using a loop, the text property isn't available, I've tried to cast the arraylist as a textbox as well, and no go.
 
arraylists holds objects (base type of all other classes) so you need to cast the object to a textbox.
Code:
ArrayList array = new ArrayList();
array.Add(new TextBox());

foreach(object o in array)
{
   TextBox box = (TextBox)o;
   box.Text = "...";
}
if you're using .net 2.0 use the List<T> class instead to create a strongly typed collection.
Code:
IList<TextBox> array = new List<TextBox>();
array.Add(new TextBox());

foreach(TextBox box in array)
{
   box.Text = "...";
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Perfect!

I kind of did a roundabout way, where I created a textbox, then made the textbox equal to the arraylist object, but yours is much, much better.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top