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 7869685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:24:19+00:00 2026-06-03T01:24:19+00:00

I am creating several text boxes depending on user choice (1-5).How can I access

  • 0

I am creating several text boxes depending on user choice (1-5).How can I access value of programmatic textbox when text changes.

class starts{
    int i=0;

    .....

    TextBox txtb4 = new TextBox();
    txtb4.Name = "textname" + Convert.ToString(i);
    ArrayText.Add(txtb4);
    System.Drawing.Point p5 = new System.Drawing.Point(120, 15);
    txtb4.Location = p5;
    txtb4.Size = new System.Drawing.Size(80, 30);
    txtb4.Text = stringMy;
    grBox1.Controls.Add(txtb4);
    i++;
}

I can access initial textbox text using code below, but I can’t access it after value is changed.

label15.Text = grBox1.Controls["textname0"].Text;
  • 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-03T01:24:20+00:00Added an answer on June 3, 2026 at 1:24 am

    Add an event handler

    txtb4.TextChanged += Txtb4_TextChanged;
    

    Declare the handler like this

    static void Txtb4_TextChanged(object sender, EventArgs e)
    {
        string s = txtb4.Text;
        ...
    }    
    

    You create textboxes dynamically; however your code looks not very dynamic. Try this

    List<TextBox> _textBoxes = new List<TextBox>();
    int _nextTextBoxTop = 15;
    
    private void AddTextBox(string initialText)
    {
        var tb = new TextBox();
        tb.Name = "tb" + _textBoxes.Count;
        _textBoxes.Add(tb);
        tb.Location = new Point(120, _nextTextBoxTop);
        _nextTextBoxTop += 36;
        tb.Size = new Size(80, 30);
        tb.Text = initialText;
        tb.TextChanged += TextBox_TextChanged
        grBox1.Controls.Add(tb);
    }
    
    static void TextBox_TextChanged(object sender, EventArgs e)
    {
        TextBox tb = (TextBox)sender;
        string s = tb.Text;
        ...
    }    
    

    And I would not access textboxes through grBox1.Controls["textname0"].Text;. The textbox list is a better choice, as you can access it through a numeric index instead of a control name

    string s = _textBoxes[i].Text;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using c# (asp.net) i'm programmatically creating several drop down lists (random number). the user
I'm creating several menu items programmatically like this : NSMenuItem* newItem = [[NSMenuItem alloc]
I'm creating several visual objects in loop: ... Package packet; // a visual packet
I just finished creating several models and a had to separately write all of
In my program, I am creating several threads in the main() method. The last
I'm creating a gem which has several scripts in the bin directory the utility
I'm creating a WPF application where several ListView selections are made in a row
While creating JavaScript with ASP.NET MVC I noticed several scope warnings and realized that
I'm creating an API for a module and after I created several methods inside
I've seen several questions/answers related to entirely creating a button in code, but not

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.