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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:52:08+00:00 2026-06-16T21:52:08+00:00

i have a windows form in which there are controls listed below panel1 button1

  • 0

i have a windows form in which there are controls listed below
panel1
button1 = add new mobiles
button2 = ok

When clicking on button1 an usercontrol is added. You can add as much userControls as you wish. The userControl defines consists of five controls:

combobox1
combobox2
textbox1
textbox2
textbox3

i want to add the text of textbox3 of all the dynamically generated usercontrol control and set to a label on the winform how can i do that? by clicking the ok button
i have tried this code

foreach (Control ctrl in panel1.Controls)
{
      if (ctrl is UserControl)
      {
           UserControl1 myCrl = ctrl as UserControl1;
           int g;
           // but this doesnt happen an error is coming
           g += Convert.ToInt32(myCrl.textbox3.Text);  
      }
}

how to get sum of all the dynamically generated control’s 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-16T21:52:09+00:00Added an answer on June 16, 2026 at 9:52 pm

    Probably your “error” is that you’re declaring g inside of the foreach loop, so you don’t actually make any sum. Furthermore, you don’t initialize it. Change your code to:

    var g = 0;
    foreach (Control ctrl in Controls)
    {
        if (ctrl is UserControl1)
        {
            var myCrl = ctrl as UserControl1;
            g += Convert.ToInt32(myCrl.textbox2.Text);
        }
    }
    //Set your label's text
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scenario. (Windows Forms, C#, .NET) There is a main form which
I have a windows-form which runs without any problem and displayed well. But if
I have a requirement to create a windows form control which has to detect
I have a windows form app, and a class which is called Game. Let's
(Modifying the question)I have a windows form app in C# which calls into some
I have a form MainForm which is a Windows Forms form that contains many
I have a program which displays an image to the windows form, and places
Im using c# .net , windows form application. I have a XML file which
I have a C# windows application which does the following: 1) the main form
I have a jQuery Model windows which contains a form. On creating of the

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.