Nov 30 2009

Improved FindControl for Windows desktop and mobile

Category: Desktop and Server | MobileJoel Ivory Johnson @ 14:45

A few days ago I posted some code containing an implementation for a Windows Forms version of FindControl. Aviad P. pointed out a correction and a way that the routine can be simlified. While I had intended the original code to do abreadth-first search it was doing a combination of depth and breadth. The functionality could also be implemented with a single loop. The result of the messages the resulting code from our communication is below.

Control FindControl(string target) {
    return FindControl(this,target);
}
static Control FindControl(Control root, string target){
    if(root.Name == target)
        return root;
    List currentLevel = new List<Control>() { root };
    while (currentLevel.Count > 0)
    {
        Control match = currentLevel.FirstOrDefault(x => x.Name == target);
        if (match != null) return match;
        currentLevel = currentLevel.SelectMany(x => x.Controls.Cast<Control>()).ToList();
    }    return null;
}

Tags: ,

Comments

1.
article submit article submit United States says:

Hmm, the project seems to have been pulled from the MSDN location where you were hosting it. Where can we get this now?

2.
meilleures promotions des casinos meilleures promotions des casinos India says:

One important distinction is a desktop version to install on a computer such as Outlook, or a Internet -based version. The latter has the advantages that it can be accessed and edited from anywhere and by different people..

Comments are closed