Click here to Skip to main content
15,897,371 members

getting sum of text from all the dynamically generated textbox

sariqkhan asked:

Open original thread
i have a windows form in which there are controls listed below
**panel1
button1
button2**
clicking on the button1 usercontrol is added on it, usercontrol can be added as much as the button is clicked means if the button1 is clicked one times then one user contorl will be added and if usercontrol is clicked twice then 2 usercontrol is added
usercontrol contains 4 controls
combobox1
combobox2
textbox1
textbox2
i want to add the text of textbox2 of all the dynamically generated usercontrol control and set to a label on the winform how can i do that?
i have tried this code
foreach (Control ctrl in panel1.Controls)
                {
                    if (ctrl is UserControl)
                    {
                        UserControl1 myCrl = ctrl as UserControl1;
                        int g;
                        g += Convert.ToInt32(myCrl.textbox2.Text);  // but 
                 this doesnt happen an error is coming
                    }
                 }

how to get sum of all the dynamically generated control's text!
Tags: C#

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900