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

  • SEARCH
  • Home
  • 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 7958221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:23:14+00:00 2026-06-04T04:23:14+00:00

So I have a form that gets dynamically generated by a script to have

  • 0

So I have a form that gets dynamically generated by a script to have a label and a text box for every string pulled as an argument. I want the user to fill in each text box then select the OK button. Afterwards I want to process each item of each text box. Before when there was only 1 item, I wrote a very simple property to obtain the value of the text box.

Public string Text { get { return textbox1.Text; } }

I was hoping I could do something equally as elegant with a dynamic number of text boxes.

Public string [] Text { get { return **Each text box text as an array**; } }

I’ve been thinking about it for a while and I can’t think of an elegant way to set this up, here is how the text boxes are added to the form…

string[] keywords = Environment.GetCommandLineArgs();
int placement = 10;
foreach (string keyword in keywords)
{
    if (keyword == keywords[0])
        continue;
    Label lbl = new Label();
    lbl.Text = keyword;
    lbl.Top = placement;
    this.Controls.Add(lbl);
    TextBox txt = new TextBox();
    txt.Top = placement;
    txt.Left = 100;
    this.Controls.Add(txt);

    placement += 20;
}

I could loop through each text box’s text upon the form closing and populate the public array with the values, but I would rather come up with something a little more elegant and get out of the habit of doing things by force. Anybody have any cool ideas of how to accomplish this? I’m thinking I could add all the text boxes to an array and then have the string property somehow grab the text of the text box specified, or just make the text box array the public property instead. Is there a way to write something like this…

Public string [] Text { get { return TextBoxArray[**value trying to be gotten**].Text; } }

or is this to much for a property and needs to be a method instead? Any other ideas anybody has? I realize it’s a bit of a trivial question and could be solved in any number of ways, I’m just looking to broaden my horizons on cool ways to accomplish something like this.

  • 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-04T04:23:15+00:00Added an answer on June 4, 2026 at 4:23 am

    Other options might be better, but this is likely the most direct and concise: (uses LINQ, add using System.Linq;, requires .NET 3.5 or higher)

    public string[] Text { get { return Controls.OfType<TextBox>().Select(x => x.Text).ToArray(); } }
    

    This is very similar to AlejoBrz’s solution, but uses LINQ to be more clear and concise.

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

Sidebar

Related Questions

I have a form that gets its names for checkboxes dynamically. Is there a
I have created a list form that gets attached to a main form in
I have a php form that gets validated through javascript. I would like to
I have a continuous form that contains a drop down box whos control source
I currently have a large form that gets sent to our payment authorizer (done
I have a form with a NumberField that gets values of type float from
I have a textbox in a form field that gets populated by the user.
I have a form that uses CKEditor and all works. I save the text
I have a page that contains a form, where part of it is dynamically
I have a form that gets submitted using jQuery's .post(). In the corresponding view

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.