Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,

Im having a problem with the textbox_textchanged event.

What i want: When I enter a number in textbox1, some math manipulation happens and the answer is displayed in textbox2. So everytime the user changes textbox1 values the answer in textbox2 should automatically change.

Now when i try to change the input value (when i backspace) the answer just goes to 0, and does changed again when I input a new value.

Am i using the wrong textbox event?

C#
private void textBox9_TextChanged(object sender, EventArgs e)
        {
            // Output Min and Max

            MaxC = Math.Round((CVAL * (1 + range)), 3);
            MinC = Math.Round((CVAL * (1 - range)), 3);
            MaxP = Math.Round((pVAL * (1 + range)), 3);
            MinP = Math.Round((pVAL * (1 - range)), 3);
            Maxsi = Math.Round((siVAL * (1 + range)), 3);
            Minsi = Math.Round((siVAL * (1 - range)), 3);
            Maxsc = Math.Round((scrap * (1 + range)), 3);
            Minsc = Math.Round((scrap * (1 - range)), 3);
            Maxtemp = Math.Round((temp * (1 + range)), 3);
            Mintemp = Math.Round((temp * (1 - range)), 3);

            textBox2.Text = Convert.ToString(MaxC);
            textBox4.Text = Convert.ToString(MinC);
            textBox10.Text = Convert.ToString(MaxP);
            textBox6.Text = Convert.ToString(MinP);
            textBox12.Text = Convert.ToString(Maxsi);
            textBox11.Text = Convert.ToString(Minsi);
            textBox14.Text = Convert.ToString(Maxsc);
            textBox13.Text = Convert.ToString(Minsc);
            textBox16.Text = Convert.ToString(Maxtemp);
            textBox15.Text = Convert.ToString(Mintemp);
        }



The variable "range" is the input from textBox9
Posted
Updated 27-Feb-12 22:00pm
v2
Comments
OriginalGriff 28-Feb-12 3:40am    
Unlikely - but we need to see the code for your TextBox.TextChanged event.
Use the "Improve question" widget to edit your question and provide better information.
P.Salini 28-Feb-12 3:44am    
post your code so that we can help you
nikki88 28-Feb-12 4:05am    
Thanks, I've posted my code

set the property(of your textbox) AutoPostBack =true
 
Share this answer
 
Comments
Dhol Gaurav 28-Feb-12 4:02am    
Bikash there are no AutoPostBack property in case of Windows Application
This correct seems to have solved the problem, thanks guys


C#
<pre lang="cs">private void textBox9_TextChanged(object sender, EventArgs e)
        {
            // Output Min and Max




           if  ((string.IsNullOrWhiteSpace(textBox9.Text)))

           {
               textBox2.Text = "";
            textBox4.Text = "";
            textBox10.Text = "";
            textBox6.Text = "";
            textBox12.Text = "";
            textBox11.Text = "";
            textBox14.Text = "";
            textBox13.Text = "";
            textBox16.Text = "";
           }

           else
           {

            range = Convert.ToDouble(textBox9.Text.Trim());

            MaxC = Math.Round((CVAL * (1 + range)), 3);
            MinC = Math.Round((CVAL * (1 - range)), 3);
            MaxP = Math.Round((pVAL * (1 + range)), 3);
            MinP = Math.Round((pVAL * (1 - range)), 3);
            Maxsi = Math.Round((siVAL * (1 + range)), 3);
            Minsi = Math.Round((siVAL * (1 - range)), 3);
            Maxsc = Math.Round((scrap * (1 + range)), 3);
            Minsc = Math.Round((scrap * (1 - range)), 3);
            Maxtemp = Math.Round((temp * (1 + range)), 3);
            Mintemp = Math.Round((temp * (1 - range)), 3);

            textBox2.Text = Convert.ToString(MaxC);
            textBox4.Text = Convert.ToString(MinC);
            textBox10.Text = Convert.ToString(MaxP);
            textBox6.Text = Convert.ToString(MinP);
            textBox12.Text = Convert.ToString(Maxsi);
            textBox11.Text = Convert.ToString(Minsi);
            textBox14.Text = Convert.ToString(Maxsc);
            textBox13.Text = Convert.ToString(Minsc);
            textBox16.Text = Convert.ToString(Maxtemp);
            textBox15.Text = Convert.ToString(Mintemp);
            }
 
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