thanks
Hello.
You'll have to build a recursive function for that. the idea is to getall the children controls and check to see if they are labels. you mustalso check if the control has any children; if it has, you have to callthe method and pass those chidren controls to it.
void CheckForLabels( ControlCollection ctls )
{
foreach( Control ctl in ctls )
{
if( ctl is Label )
{
//do your stuff here
}
if( ctl.Controls.Count != 0 )
{
CheckForLabels( ctl.Controls )
}
}
}
Please keep in mind that:
1.) i've jsut written this code so it may contain bugs (the objective is to demonstrate the idea)
2.) the best place to start is (maybe) the control collection of the form since you'll declare all the controls inside it
depending on your naming convention of the Lables in question, it could be a lot easier/faster than that
Hello.
yes it could if, for instance, you had the name of the labels on aarray or something like that. however, if you're writing generic code,i think that you'll have to go through all the controls that exist onthe page.
Thanks for this, it looks like the sort of thing I need.
I am clueless though with C#, I couldn't translate that to VB if my life depended on it.
Any chance of a VB version?
thanks
Private Sub CheckForLabels(ControlCollection as Control)
Dim ThisLabel As Label
For Each ChildControl in ControlCollection.Controls
If TypeOf ChildControl Is Label then
ThisLabel = CType(ChildControl, Label)
'Do your code here to "ThisLabel"
End If
CheckForLabel(ChildControl)
Next
End Sub
i'm just going to re-itterate though, if the labels you are after are labeled in some logical sense, like Label_1, Label_2, Label_3, etc... the code could be faster/better
wonderful, it works perfectly, thank you very much indeed !
0 comments:
Post a Comment