Accessing Form Controls in VSTA ---Problem - InfoPath Dev
in

InfoPath Dev

Accessing Form Controls in VSTA ---Problem

Last post 07-12-2007 08:29 PM by Curious. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-09-2007 01:20 AM

    Accessing Form Controls in VSTA ---Problem

    Hi IP Gurus

        When using VS 2003 for coding IP 2003 form we were using this syntax to access a textbox property: thisXDocument.DOM.selectSingleNode("my:myFields/my:field1").text. Similarly to access a radio button we were using

    IXMLDOMNode myRadioButton = thisXDocument.DOM.selectSingleNode("my:myFields/my:radioButtonPersonal"); and then myRadioButton.text etc.

    However the above syntax did not work for IP 2007 form using VSTA. Can anyone please help that how can one access the textboxes and other form controls in IP 2007 forms using VSTA in C# code.
     

     

    thanks in advance 

    _____________________
    The Passionately Curious!
  • 07-09-2007 01:49 AM In reply to

    Re: Accessing Form Controls in VSTA ---Problem

    IP 2007 object model is a bit different. instead of using thisXDocument have a look for XPathNavigator.

    Hope this helps

    Listen to Motörhead cos they play Rock'n Roll :)
  • 07-09-2007 11:19 AM In reply to

    Re: Accessing Form Controls in VSTA ---Problem

    Yes, the OM has changed a lot and now you have to use Navigators... here is an example:

    XPathNavigator rootNavigator = this.MainDataSource.CreateNavigator();
    XPathNavigator radioButtonPersonal = rootNavigator.SelectSingleNode("/my:myFields/my:radioButtonPersonal", this.NamespaceManager);
    radioButtonPersonal.SetValue(
    "2");

    XPathNavigator rootNavigator = this.MainDataSource.CreateNavigator();
    XPathNavigator radioButtonPersonal = rootNavigator.SelectSingleNode("/my:myFields/my:radioButtonPersonal", this.NamespaceManager);
    radioButtonPersonal.SetValue(
    "2");

    A few interesting points:

    - Unlike in 2003, you need to pass the namespaceManager in explicitly or else prefixes such as "my" won't resolve.
    - Navigators are tricky beasts - unlike IXMLDOMNode objects, they are merely pointers into the XML tree and can change under you. If you pass navigators along, it might be wise to call Clone() on them - a navigator clone is not an expensive operation.
    - To get node's value, you can use the Value property, but it cannot be assigned to to set value you have to call SetValue(). The value property will be empty for inner nodes - use InnerXml instead.

    Hope this helps!

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-12-2007 08:29 PM In reply to

    Re: Accessing Form Controls in VSTA ---Problem

    thanks!!!!!!!!
    _____________________
    The Passionately Curious!
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.