need help with syntax for getting and setting value of InfoPath 2007 check box - InfoPath Dev
in

InfoPath Dev

need help with syntax for getting and setting value of InfoPath 2007 check box

Last post 07-11-2009 09:48 AM by gerry lowry. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-10-2009 03:07 PM

    • gerry lowry
    • Not Ranked
      Male
    • Joined on 07-09-2009
    • alliston ontario canada
    • Posts 21

    need help with syntax for getting and setting value of InfoPath 2007 check box

    Hello, I need help with syntax for getting and setting value of an InfoPath 2007 check box.
     
    Please note:  I am using InfoPath 2007 on the desktop, not the web form version.
     

    public void startLesson_Clicked(object sender, ClickedEventArgs e)
    {
     
    XPathNavigator myNavigator = this.MainDataSource.CreateNavigator();
     
    XPathNavigator myGclassLicense = this.MainDataSource.CreateNavigator()
                                                                         .SelectSingleNode(
    "/my:lessonData/my:lessonFields/my:GclassLicense", NamespaceManager);
     
    while (true)
      {
        
    if (myGclassLicense != null) break;
        
    MessageBox.Show("lesson can not precede; driver is not licensed.");
        
    return;
      }

    The first time through to above code, after the form has been loaded, the check box is unchecked.
    The code appears to work because, myGclassLicense is null.

    However, when I then click the check box, even though visually it is checked, myGclassLicense is still null.

    I assume that somehow I am not getting the correct value, probably because I am not using the correct syntax.

    What am I missing here?

    Please advise.

    Also, what is the c# syntax for setting the value of an Infopath 2007 check box?

    Thank you.

     

    Regards,
    Gerry (Lowry)

    Gerry Lowry, Principal
    Ability Business Computer Services ~~ Because it's your Business, our Experience Counts!
    68 John W. Taylor Avenue
    Alliston · Ontario · Canada · L9R 0E1 · [email protected]
  • 07-10-2009 05:27 PM In reply to

    Re: need help with syntax for getting and setting value of InfoPath 2007 check box

    Hi:

    The XPathNavigator gets the form node. We use XPathNavigator.Value to get the value and .SetValue("newValue") to set the value.

    So, if your XPathNavigator myGclassLicense were successfully returning a node (instead of null), you'd get the value like myGclassLicense.Value and you'd set the value like myGclassLicense.SetValue("newValue").

    The question, then, is why you aren't getting a node with the XPath "/my:lessonData/my:lessonFields/my:GclassLicense"

    Did you use the 2007 'Copy XPath' to copy the XPath from the main data source in the data source task pane? That is the best way to avoid XPath mistakes (love that feature...).

    Oh, also:
    XPathNavigator myNavigator = this.MainDataSource.CreateNavigator(); 
    XPathNavigator myGclassLicense = this.MainDataSource.CreateNavigator()
                                                                         .SelectSingleNode(
    "/my:lessonData/my:lessonFields/my:GclassLicense", NamespaceManager);

    Should more likely be:
    XPathNavigator myNavigator = this.MainDataSource.CreateNavigator();
    XPathNavigator myGclassLicense = myNavigator.SelectSingleNode("/my:lessonData/my:lessonFields/my:GclassLicense", NamespaceManager);

    Hilary Stoupa

  • 07-11-2009 09:48 AM In reply to

    • gerry lowry
    • Not Ranked
      Male
    • Joined on 07-09-2009
    • alliston ontario canada
    • Posts 21

    Re: need help with syntax for getting and setting value of InfoPath 2007 check box

    Thank you, Hilary ... you nailed it:  typo on my part:  License (U.S. spelling) instead of Licence (British Spelling).

    I'm Canadian ... mostly we use British Spelling, but not always.   Since we are bilingual (British English and U.S. English) it's not unusual for us to mangle both languages.

    I like the 'Copy XPath' too but it's tempting not to use it for every field when one has 50+ fields.

     

    Hilary, I truly appreciate your help. 

    Gerry

     

    Gerry Lowry, Principal
    Ability Business Computer Services ~~ Because it's your Business, our Experience Counts!
    68 John W. Taylor Avenue
    Alliston · Ontario · Canada · L9R 0E1 · [email protected]
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.