Click here to Skip to main content
11,433,220 members (57,938 online)
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 26-Sep-12 0:19am
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)



Advertise | Privacy | Mobile
Web04 | 2.8.150428.2 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2015
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