Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Desktop Developer

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Foundations of Programming EbookSolution folders are not being sorted alphabeticaly in Visual studio 2008 »
    comments

    Use the power of linq

    Create a form with some controls on it and a textbox called textbox1.

    then but this in the load event of the form

    1. textBox1.Clear();
    2.             IEnumerable<Control> query = from p in this.Controls.OfType<Control>() orderby p.TabIndex select p;
    3.             foreach (Control c in query)
    4.             {
    5.                 textBox1.AppendText(c.TabIndex + " " + c.Name + Environment.NewLine);    
    6.             }

    and you probably need these usings.

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Windows.Forms;

    At first I couldn’t get it to work until I found this LINQ - Query Windows Forms Controls
    by Sam Allen
    and then the light came. I was missing the TypeOf method. This is really cool. No more reflection needed to get that control you realy need.

    About the Author

    User bio imageChris is awesome.
    Social SitingsTwitterHomePageLTD RSS Feed
    InstapaperVote on HN

    3 comments

    Comment from: cnc machine [Visitor]
    cnc machine Frantically been searching everywhere on information regarding this. Really thanks a lot.
    01/31/11 @ 21:47
    Comment from: Jonathan Wood [Visitor] · http://www.blackbeltcoder.com
    Jonathan Wood There are things I don't like about LINQ. Namely, that it takes me further away from what's happening under the covers. But I must admit stuff like this is pretty cool. Perhaps I'll have to spend a bit more time with LINQ.
    02/05/11 @ 22:50
    Comment from: Chris [Visitor]
    Chris Many thanks for this - saved me much time.
    10/29/11 @ 18:37

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)