locked
Suppress TextChanged event RRS feed

  • Question

  • I have some text boxes that bind to a bindingsource. Each also has it's TextChanged event handler set, so if the user changes the text, a Save button is enabled. The problem is that when BindingSource.Current is changed, that repopulates the text boxes, which in turn raises TextChanged event, which enables the button. Is there a way to suppress the TextChanged event? DGV control has EndEdit event handler, but TextBoxes do not have that.

    Monday, March 14, 2011 5:20 AM

Answers

  • Hi,

    I am affraid if you have this event for the button (or any other control which supports it), and when the the text in this control is being changed, the event TextChanged will be rised. But you can do one thing with will work pretty well. You can use boolean flag. An example:

        bool bChecking;
        private void YourMethodOfPopulation()
        {
          //1st set the flag to true, so the code in TextChanged event wont be rised:
          bChecking = true;
          //then do the code with dataBinding or what ever
    
          //on the end set the flag back to false, so the code in the even can be executed when will be really needed (when pressinf keys)
          bChecking = false;
        }
    
        private void textBox_TextChanged()
        {
          if (!bChecking)
          {
            //do the real code for textChecged!
          }      
        }
    

     

    Mitja

    • Proposed as answer by Helen Zhou Monday, March 14, 2011 9:44 AM
    • Marked as answer by Helen Zhou Wednesday, March 23, 2011 9:51 AM
    Monday, March 14, 2011 7:02 AM