locked
TextChange Event triggers When text does not change! RRS feed

  • Question

  • Hi,

    I am puzzled.

    In the code below, I have a text box with a "1" in it, initially.

    The code below makes sure that only "1" and "0" are allowed to be entered.

    If the entry is correct the variable 'digitalC' will update accordingly.

    The problem is when you type "1", or "0", when there is already a "1" or "0" in the textBox.

    The 'TextChanged' event trigger anyway.

    I would expect that if you type "1", where there is already a "1", the event should not trigger!

    Please, can anyone tell me what is wrong in the code?

    Regards

    Francesco

     
            // *************  Digital input 0  ***************************//
            private void textBox1_TextChanged(object sender,EventArgs e)
                {
                string digi0 = textBox1.Text;
                if(digi0=="1")
                    {
                    //action
                    digitalC=digitalC+1;
                    textBox14.Text=digitalC.ToString();
    
                    }
                else if(digi0=="0")
                    {
                    //action
                    digitalC=digitalC-1;
                    textBox14.Text=digitalC.ToString();
                    }
                else
                    {
                    //action
                    wrongDigit();    // Do Message "Wrong Digit"
                    //default digit 1
                    textBox1.Text="1";
                    
                     }
    
                }


    • Moved by Dave PatrickMVP Monday, March 18, 2019 9:41 PM looking for forum
    Monday, March 18, 2019 9:32 PM

Answers