Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 25-Sep-12 23:19pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

for each text box write a TextChanged Event handler on that write below mentioned code
private void tbx1_TextChanged(object sender, EventArgs e)
{
   try
   {
      tbx_TotalSum.Text=tbx1.Text+ .....+tbxn.Text;
   }
   catch
   {
      throw;
   }
}
  Permalink  
Comments
aarohi verma at 26-Sep-12 6:12am
   
I do this but its not changing my total text box value.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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).
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Comments
Killzone DeathMan at 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)

  Print Answers RSS
0 Maciej Los 225
1 OriginalGriff 145
2 manoj kumar choubey 115
3 _Amy 115
4 Sergey Alexandrovich Kryukov 105
0 OriginalGriff 7,320
1 Sergey Alexandrovich Kryukov 6,043
2 Maciej Los 3,749
3 Peter Leow 3,408
4 DamithSL 2,555


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100