Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8177151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:26:20+00:00 2026-06-06T23:26:20+00:00

I have a few different TextBox elements named as followed e0, e1, e2, e3.

  • 0

I have a few different TextBox elements named as followed “e0”, “e1”, “e2”, “e3”. I know how many there are and I just want to be able to loop through them and grab their values rather than typing each one out manually.

I’m assuming I’ll be doing something like this, I just don’t know how to access the element.

for(int i= 0; i < 4; ++i) {
    string name = "e" + i;
    // How do I use my newly formed textbox name to access the textbox 
    // element in winforms?
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:26:21+00:00Added an answer on June 6, 2026 at 11:26 pm

    I would advise against this approach since it’s prone to errors. What if you want to rename them, what if you’ll forget about this and add other controls with name e...?

    Instead i would collect them in a container control like Panel.
    Then you can use LINQ to find the relevant TextBoxes:

    var myTextBoxes = myPanel.Controls.OfType<TextBox>();
    

    Enumerable.OfType will filter and cast the controls accordingly. If you want to filter them more, you could use Enumerable.Where, for example:

    var myTextBoxes = myPanel.Controls
                             .OfType<TextBox>()
                             .Where(txt => txt.Name.ToLower().StartsWith("e"));
    

    Now you can iterate those TextBoxes, for example:

    foreach(TextBox txt in myTextBoxes)
    {
        String text = txt.Text;
        // do something amazing
    }
    

    Edit:

    The TextBoxes are on multiple TabPages. Also, the names are a little
    more logical …

    This approach works also when the controls are on multiple tabpages, for example:

    var myTextBoxes = from tp in tabControl1.TabPages.Cast<TabPage>()
                      from panel in tp.Controls.OfType<Panel>()
                      where panel.Name.StartsWith("TextBoxGroup")
                      from txt in panel.Controls.OfType<TextBox>()
                      where txt.Name.StartsWith("e")
                      select txt;
    

    (note that i’ve added another condition that the panels names’ must start with TextBoxGroup, just to show that you can also combine the conditions)

    Of course the way to detect the relevant controls can be changed as desired(f.e. with RegularExpression).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few different tables that I want to display vertically down a
I have a few different Google Charts that i want to put inside the
I am writing an application, where I do have few different windows implemented, where
I have a few different applications that i need to share code between to
I have a few different things open in the terminal whenever I'm developing --
We have a few different programs all compiled together in the same suite, recently
I have a few different classes which origin is a another class. I have
Background : I have a few different threads which each need to write to
I have defined a few different functions in my .bash_profile . I usually remember
I have tried this a few different ways and it always seems to fail.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.