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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to identify TextBox,RadioButtons etc

Status
Not open for further replies.

vladibo

Programmer
Sep 14, 2003
161
CA
How to identify TextBox,RadioButtons if they are not class properties?

I would like to ask about form elements like TextBox or RadioButtons, can I identify their content by some other way than with inner class properties. I mean that they are generated dynamicly and I can not know what class properties to create for them, so how to find what are their values.

Example:
class MyClass: Form{

MyClass(ArrayList a){
for(int i=0;i<a.Count;i++){
TextBox t = new TextBox();
t.Text = a.get_Item(i);
t.Dock = DockStyle.Top;
this.Controls.Add(t);
}
}

void Run(){
// How can I find the content of my TextBoxes here?
}

}

Thanks
 
Hi there,

You need to iterate on the Controls collection of the form.

For instance:
Code:
foreach (object obj in this.Controls)
{
	if (obj is TextBox)
	{
		TextBox txt = (TextBox)obj;
                // do something
	}
}
Hope this helps.
Cheers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top