Copying values from repeating table into Rich Text Box in Browser Form - InfoPath Dev
in

InfoPath Dev

Copying values from repeating table into Rich Text Box in Browser Form

Last post 03-16-2011 03:54 PM by JGalt. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 03-16-2011 02:11 PM

    • JGalt
    • Not Ranked
    • Joined on 02-11-2011
    • Posts 3

    Copying values from repeating table into Rich Text Box in Browser Form

    Hi All,

    I am attempting to read the values from a field  (rt1) in a repeating table (group2) and take those values and write them to a rich text box control (richtext) in a browser form using InfoPath 2007.

    Once I get this working, I plan to add more fields, lay them out in tables and combine them with other HTML formatted text and values from other textboxes.

    It works ok with 2 exceptions

    1. The HTML formatting doesn't seem to work at all
    2. I'm only getting the first record, it ignores any records after the first so I assume I'm doing this wrong.

    I'm relying on this post http://www.bizsupportonline.net/infopath2007/programmatically-add-text-lines-rich-text-box-infopath-code.htm as well as some other examples of how to read from repeating tables.

     Can anyone tell me what the problem is? Code below.

     Thanks

     

    XPathNavigator nav = MainDataSource.CreateNavigator();

    XPathNavigator rtfNav = nav.SelectSingleNode("//my:richtext", NamespaceManager); XPathNavigator navigator = CreateNavigator();

    XPathNodeIterator nodes = navigator.Select("/my:myFields/my:group1/my:group2", NamespaceManager);

    while (nodes.MoveNext())

    {

    using (XmlWriter writer = rtfNav.AppendChild())

    {

    writer.WriteStartElement("p", "http://www.w3.org/1999/xhtml");

    writer.WriteString(nodes.Current.SelectSingleNode("/my:myFields/my:group1/my:group2/my:rt1", NamespaceManager).Value);

    writer.WriteEndElement();

    writer.Close();

    }

     

    }

     

  • 03-16-2011 03:07 PM In reply to

    • JGalt
    • Not Ranked
    • Joined on 02-11-2011
    • Posts 3

    Re: Copying values from repeating table into Rich Text Box in Browser Form

    Managed to get the loop to work. Unfortunately the HTML formatting the way I am attempting with Writer.StartElement ("b", "http://www.w3.org/1999/xhtml"); still does not. 

     

    XPathNodeIterator nodes = MainDataSource.CreateNavigator().Select("/my:myFields/my:group1/my:group2", this.NamespaceManager);

    XPathNavigator nav = MainDataSource.CreateNavigator();

    XPathNavigator rtfNav = nav.SelectSingleNode("//my:richtext", NamespaceManager);

    string field1 = string.Empty;

    string field2 = string.Empty; string field3 = string.Empty;

    string field5 = string.Empty;

    foreach (XPathNavigator node in nodes)

    {

    field1 = node.SelectSingleNode("my:rt1", this.NamespaceManager).Value;

    field2 = node.SelectSingleNode("my:rt2", this.NamespaceManager).Value; field3 = node.SelectSingleNode("my:rt3", this.NamespaceManager).Value;

    field5 = node.SelectSingleNode("my:rt1", this.NamespaceManager).Value + " " + node.SelectSingleNode("my:rt2", this.NamespaceManager).Value + " " + node.SelectSingleNode("my:rt3",  this.NamespaceManager).Value;

    using (XmlWriter writer = rtfNav.AppendChild())

    {

    writer.WriteStartElement(
    "b", "http://www.w3.org/1999/xhtml");

    writer.WriteString(field5);

    writer.WriteEndElement();

    writer.Close();

    }

    }

  • 03-16-2011 03:54 PM In reply to

    • JGalt
    • Not Ranked
    • Joined on 02-11-2011
    • Posts 3

    Re: Copying values from repeating table into Rich Text Box in Browser Form

    Well it looks like the examples I had seen about the formatting were slightly wrong.

    To make it work you have to use

    writer.WriteStartElement("", "p", http://www.w3.org/1999/xhtml);

    instead of

    writer.WriteStartElement("p", http://www.w3.org/1999/xhtml);

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