how can I override (?) the changed event - InfoPath Dev
in

InfoPath Dev

how can I override (?) the changed event

Last post 05-21-2009 10:17 AM by tfiema. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 05-20-2009 02:33 PM

    • tfiema
    • Not Ranked
    • Joined on 09-17-2008
    • Posts 6

    how can I override (?) the changed event

    I have 2 text boxes when the value in tb1 changes the changed event fires and sets the tb2 value to a number calucluated based on tb1.

    But, I need tb1 to do the same based on tb2.

    The problem is that the changed events will fire in sequece until the values stop changing. They will keep changing cause the values get rounded.

    anyhow, this is confusing to explain. Simply said: I would like to update tb2 and not have it's changed event fire becuase I'm changing it from code.

    ANy tips would be welcome.

     

  • 05-20-2009 04:59 PM In reply to

    Re: how can I override (?) the changed event

    Hi tfiema,

    A possible solution for this is to implement code that removes the eventhandler from textbox 2 before changing it's value and re-add the eventhandler after the value is changed.

    For example:

    You need to have 2 change events, one for Textbox1 and one for Textbox2:

    public void changeTextbox1Event()
    {
      Remove the eventhandler of TextBox2;
      Change the value of Textbox2 according to value in Textbox1;
      Re-Add the eventhandler to Textbox2;
    }

    public void changeTextbox2Event()
    {
      Remove the eventhandler of TextBox1;
      Change the value of Textbox1 according to value in Textbox2;
      Re-Add the eventhandler to Textbox1;
    }

    Let me know if this idea works for you.

  • 05-21-2009 03:47 AM In reply to

    Re: how can I override (?) the changed event

    It's not as elegant as removing events, but I would add a 3rd element to store the name of the trigger element and test for that when each event fires.

    private void TextBox1_Changed(object sender, XmlEventArgs e)
    {
    if (ReadElement("EventFiredByElement") != "TextBox2")
    {
       SetElement("EventFiredByElement", "TextBox1");
       DoWorkOnTextBox2();
    }
    }

    private void TextBox2_Changed(object sender, XmlEventArgs e)
    {
    if (ReadElement("EventFiredByElement") != "TextBox1")
    {
       SetElement("EventFiredByElement", "TextBox2");
       DoWorkOnTextBox1();
    }
    }

    private void DoWorkOnTextBox2()
    {
       //do some work on TextBox2...
       //Clear EventFiredBy field when finished
       SetElement("EventFiredByElement","");
    }

    private void DoWorkOnTextBox1()
    {
       //do some work on TextBox1...
       //Clear EventFiredBy field when finished
       SetElement("EventFiredByElement","");
    }

    I *think* that would work.

    Craig

  • 05-21-2009 10:17 AM In reply to

    • tfiema
    • Not Ranked
    • Joined on 09-17-2008
    • Posts 6

    Re: how can I override (?) the changed event

    OK, thanks guys. Those were good.

    I couldn't figure out how to bind the event handler ouside of startup, so I ended up going with a temp holder storing the identifier of which tb is actually changing.

    so each tb changed event looked like this. At the start it checks what is being chaged to make sure it should run:

    (this is for tb1)

    string changing = MainDataSource.CreateNavigator().SelectSingleNode("/my:Form/my:changing";, NamespaceManager).Value;

    if (e.Operation == XmlOperation.ValueChange && (changing == "" || changing == "tb1"))

    {

    MainDataSource.CreateNavigator().SelectSingleNode("/my:Form/my:changing";, NamespaceManager).SetValue("tb1");

    MainDataSource.CreateNavigator().SelectSingleNode("/my:Form/my:tb2";, NamespaceManager).SetValue("my new value");

    //tb2 changed event will not fire because my:changing is set to "tb1".

    MainDataSource.CreateNavigator().SelectSingleNode("/my:Form/my:changing";, NamespaceManager).SetValue("");

    }

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.