Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have following fields in the application as follows:
Eligibility Leave    36   Texbox1
Availed  Leave        3   Textbox2
Balance              33   Textbox3

When I type Availed Leave 3 in Textbox2, I want the output as 33 (Balance).
C#
private void txt_availed_TextChanged(object sender, EventArgs e)
       {

       }

Please send the code.

Regards,
Rao.
Posted
Updated 14-Nov-12 23:07pm
v2

C#
private void txt_availed_TextChanged(object sender, EventArgs e)         
{
            int eligibility = 0;
            int availed = 0;
            bool isValidValue = true;

            try
            {
                eligibility = int.Parse(textBox1.Text);
            }
            catch
            {
                isValidValue = false;
            }

            try
            {
                availed = int.Parse(textBox2.Text);
            }
            catch
            {
                isValidValue = false;
            }

            if (isValidValue)
            {
                textBox3.Text = (eligibility - availed).ToString();
            }
            else
            {
                textBox3.Text = "";
            }
        }
 
Share this answer
 
Comments
Mohd. Mukhtar 15-Nov-12 4:46am    
Please avoid using these many try catch blocks.
C#
if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text))
            {
                textBox3.Text = (int.Parse(textBox1.Text) - int.Parse(textBox2.Text)).ToString();
            }
            else
            {
                textBox3.Text = "";
            }
 
Share this answer
 
C#
try
            {
                textBox3.Text = (int.Parse(textBox1.Text) - int.Parse(textBox2.Text)).ToString();
            }
            catch
            {
                textBox3.Text = "";
            }
 
Share this answer
 

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