Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

I have several textboxes (10 or 11) in my form, and one textbox for total,

i want result for this

in my total textbox default value is 0 but when i input values in another textboxes it changes value in my total textbox.

so how can i do this.
Posted

for each text box write a TextChanged Event handler on that write below mentioned code
C#
private void tbx1_TextChanged(object sender, EventArgs e)
{
   try
   {
      tbx_TotalSum.Text=tbx1.Text+ .....+tbxn.Text;
   }
   catch
   {
      throw;
   }
}
 
Share this answer
 
Comments
aarohi verma 26-Sep-12 6:12am    
I do this but its not changing my total text box value.
Update the total textbox value (that is perform the sum) in the TextChanged[^] event handler of any of the other textboxes (you may associate the same event handler to all such textboxes).
 
Share this answer
 
at leave event of every text box except the total one write this

decimal sum
sum = convert.todecimal(textbox1.text) + convert.todecimal(textbox2.text) +convert.todecimal(textbox3.text)
txttotal.text = sum
 
Share this answer
 
Comments
Killzone DeathMan 26-Sep-12 7:09am    
try
{
decimal sum = 0;

sum = Convert.ToDecimal(textbox1.Text) + Convert.ToDecimal(textbox2.Text) +
Convert.ToDecimal(textbox3.Text);

txttotal.Text = sum.ToString();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"Error");
}

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