Reference controls on the form 'dynamiclly'

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Is it possible to do, to get to the control by its name dynamiclly. ASP.NET
has .FindControl("") method to do that, is there a similary method in
winforms.

Thanks.
 
Lenn said:
Is it possible to do, to get to the control by its name dynamiclly. ASP.NET
has .FindControl("") method to do that, is there a similary method in
winforms.

I don't think there's a method anywhere that does this. You could
implement it yourself, like this (untested):

Control FindControl(string name, Control searchControl) {
if (searchControl.Name == name)
return searchControl;

foreach (Control childControl in searchRoot.Controls) {
Control foundControl = FindControl(name, childControl);
if (foundControl != null)
return foundControl;
}

return null;
}


Oliver Sturm
 
I should probably mention that this approach is certainly not very
performant - what exactly do you want to do? Are you sure it's the best
idea to search for a control by its name?



Oliver Sturm
 
I simply want to load application configuration from IsolatedStorage to some
object say hashtable. When user selects setting menu, I want to show this
settings on the form in textboxes. So instead of doing this:

txtSomeSetting.text = oHashTable["key"].ToString()
txtAnotherSetting.text = oHashTable["Anotherkey"].ToString()

I though it would be nice to do the following:
FindControl("key").text = oHashTable["key"].ToString()
 
Back
Top