FindControl for Windows Mobile using C#

No.of Views1614
Bookmarked0 times
Downloads 
Votes0
By  j2inet   On  11 Jul 2010 02:07:48
Tag : Windows Mobile , Miscellaneous
An improved FindControl for Windows desktop and mobile.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

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 a breadth-first search, it was doing a combination of depth and breadth. The functionality could also be implemented with a single loop.

CodeSnippet

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() { 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()).ToList();
    }return null;
}

Happy coding.

 
Sign Up to vote for this article
 
About Author
 
j2inet
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Not Provided
Joined date-12 Jun 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top