Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I HAVE URGENT PROJECT NOW..

how to addition using in multiple textboxes

pls help me

C#
c = double.Parse(textBox21.Text)+ double.Parse(textBox22.Text);
i =  double .Parse (textBox23.Text);
textBox31.Text = Convert.ToDouble(c + i ).ToString();
return;



next wat i do....30textbox i used to calculate in addition method
Posted
Updated 15-Jul-12 23:27pm
v3
Comments
Sebastian T Xavier 16-Jul-12 5:27am    
use small caps
[no name] 16-Jul-12 7:46am    
You have already asked this and have an answer

Hi ,
Check this
C#
 double sum = 0;
 foreach (Control c in this.Controls)
 {
     if (c is GroupBox)
     {
         foreach (Control item in c.Controls)
         {
             if (item is TextBox)
             {
                 sum += Convert.ToDouble(((TextBox)item).Text);
             }
         }
     }
 }

MessageBox.Show(sum.ToString());


Best Regards
M.Mitwalli
 
Share this answer
 
v3
Comments
Nilesh Patil Kolhapur 16-Jul-12 6:00am    
this is a wrong way because this uses all textboxs
Mohamed Mitwalli 16-Jul-12 6:08am    
if it textbox placed in Container like Groupbox or panel it will work fine so i suggest he put all this controls in Container .
Nilesh Patil Kolhapur 16-Jul-12 6:10am    
ok then thats fine sir
Hi,

try this
C#
double sum=double.Parse(textBox21.Text)+ double.Parse(textBox22.Text)+double.Parse(textBox23.Text)+ double.Parse(textBox24.Text)+.............+double.Parse(textBox29.Text)+ double.Parse(textBox30.Text) 

textBox31.Text =sum.toString();
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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