Xblog.org

>> Home


Locations of visitors to this page

18 June 2008

A WinForms missing method

I'm sure I can't be the only person to need this so here is a function I couldn't find :-

private Control FindControl(string strControlName)
{
    if (String.IsNullOrEmpty(strControlName) || this.Controls.Find(strControlName, true).Length == 0)
        return null;

    return this.Controls.Find(strControlName, true)[0];
}

Usage :-

for (int p = 0; p < CurrentMap.Depth_Tiles; p++)
{
    string strOutput = String.Format("CheckBox Controle cbShowLayer{0} - ", p);

    if (((CheckBox)FindControl("cbShowLayer" + p.ToString())).Checked == true)
        MessageBox.Show(strOutput + "checked");
    else
        MessageBox.Show(strOutput + "not checked");
}

If anyone has a better solution let me know :-)

Labels: ,

posted by Dave Henry at  

0 Comments:

Post a Comment

Links to this post:

Create a Link