Setting the value of a formatted text field in C# - InfoPath Dev
in

InfoPath Dev

Setting the value of a formatted text field in C#

Last post 06-03-2008 08:45 AM by InfoPathN00b. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-03-2008 03:24 AM

    Setting the value of a formatted text field in C#

    I have a text field with a Data type of Whole Number (integer) the value of which I need to set in code (C# on InfoPath 2007)

    XPathNavigator txtField = this.CreateNavigator().SelectSingleNode("/my:myFields/my:txtField", this.NamespaceManager);         
               txtField.SetValue(10);
    Unfortunately the setValue method only takes a string parameter.

    txtField.SetValue("10");

    gives the runtime error 'Schema bvalidation found non-data type errors.' The detail says 'System.InvalidOperationException'

  • 06-03-2008 07:29 AM In reply to

    Re: Setting the value of a formatted text field in C#

    You need to remove the Nil attribute:

    public void DeleteNil(XPathNavigator node){if (node.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))      node.DeleteSelf();

    }

    DeleteNil(this.CreateNavigator().SelectSingleNode("/my:myFields/my:txtField", this.NamespaceManager));

    XPathNavigator txtField = this.CreateNavigator().SelectSingleNode("/my:myFields/my:txtField", this.NamespaceManager);         
               txtField.SetValue(10);
    txtField.SetValue("10");

    http://blogs.msdn.com/infopath/archive/2006/11/28/the-xsi-nil-attribute.aspx

  • 06-03-2008 08:45 AM In reply to

    Re: Setting the value of a formatted text field in C#

     Thanks Koen that fixed the problem even if I'm not so impressed by them putting the entire method on one line.

     

            public void deleteNil(XPathNavigator node)
            {
                if (node.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))
                {
                    node.DeleteSelf();
                }
                else { }
            }

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