Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

In Web development wa can use a method called System.Web.UI.Control.FindControl(string) to get a control by its ID. So in a Page (inheriting from Control by default) we can easily get any control of that page.

 

Do I have missed the equivalent of that function for the System.Windows.Forms.Control ?

I know we have access to the ControlCollection of a form but if I have a textBox on my Form named "TextBox1", how can I get it ? (can't use me.TextBox1 if the control has been added dynamically)

No other solution to get an enumerator on the ControlCollection and test all control ????

 

Thanks,

Jarod
  • *Gurus*
Posted
You'd have to loop through checking their .Name property I suppose. Controls don't really have names as such, so if you're creating them at runtime it's best to keep a reference to them around somewhere, either in a hashtable or you can just rely on the .Name property and loop through the Controls collection.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...