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.
Oliver Sturm - 08 Aug 2005 19:04 GMT
> 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

Signature
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Oliver Sturm - 08 Aug 2005 19:08 GMT
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

Signature
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Lenn - 08 Aug 2005 20:27 GMT
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()
> 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
Herfried K. Wagner [MVP] - 08 Aug 2005 19:23 GMT
"Lenn" <Lenn@discussions.microsoft.com> schrieb:
> 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.
There is no direct equivalent to Web Form's 'FindControl' method.
Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>

Signature
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>