Line break - InfoPath Dev

InfoPath Dev

Use our Google Custom Search for best site search results.

Line break

Last post 01-15-2015 02:08 PM by lockettc. 29 replies.
Page 1 of 2 (30 items) 1 2 Next >
Sort Posts: Previous Next
  • 12-20-2005 07:29 AM

    Line break

    Hi Folks,

    seems to be a simple task but...
    I am writing text (string) programmatically into a infopath text box. Some how it is not possible to enforce a line break.
    Does someone know where the problem is. Is it about the textbox or is it about code. I was using System.Environment.Newline and usually works always.

    Thx in advance

    Listen to Motörhead cos they play Rock'n Roll :)
    Listen to Motörhead cos they play Rock'n Roll :)
  • 12-20-2005 07:40 AM In reply to

    First, you must make sure that your textbox is formatted to be able to display paragraph breaks. To do this double-click on the text box control, go to the Display tab, and check the checkbox labeled "Allow paragraph breaks".

    After this, your code should work, but if it still doesn't try using "\n" instead of the System.Environment.Newline.

    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 12-20-2005 07:48 AM In reply to

    Thx again Matt.

    It works. The Paragrph breaks option wasn't checked.

    Listen to Motörhead cos they play Rock'n Roll :)
    Listen to Motörhead cos they play Rock'n Roll :)
  • 04-26-2009 09:52 PM In reply to

    Hi, I am having the same issue.

    I am using Visual Studio Tools for Applications to edit code of an Infopath 2007 form.
    I use the following line to add the contents of a field to another and then add a line break to the end.

    field1 = field1 & field2 & System.Environment.NewLine

    The two fields are added together sucessfully, but the new line does not appear.

    The text boxes have paragraph breaks enabled.
    I have also tried the "\n" but all that does is adds "\n" as text to the field.

    Any ideas?

  • 04-29-2009 03:25 PM In reply to

    Interesting that there's a few having this challenge.

    I need to bind my control to a Secondary Data Source, so whichever control works best, I'm all for. Currently I'm using an Expression Box because it allows a formula to be used. I've used concat to display mulitple columns of data from my SharePoint site but they just come out as one long string. Adding a line break/paragraph between each is what I'm after.

    So my expression starts out as this: concat(@RelDateA, @RelDateB, @RelDateC)

    If I could use "chr(10)/chr(13)" I would, but I'm not sure how to add it. Same with the "\n" -- I'm not familiar with how to add it...

    Any more help on this?

  • 04-29-2009 04:22 PM In reply to

    Hi again,

    I got it to work finally.
    I can't remember exactly where I found this solution, but it works, so i'm happy ... for now ;)

    Dim ns As XmlNamespaceManager = Me.NamespaceManager
    Dim textfield As XPathNavigator = MainDataSource.CreateNavigator().SelectSingleNode("/my:My_Fields/my:RichTextField", ns)

    textfield.InnerXml = textfield.InnerXml & "<div xmlns="""" />"

  • 04-29-2009 04:30 PM In reply to

    You totally lost me on that... :(

  • 04-29-2009 07:10 PM In reply to

    Hello Mr. Palmer,

     Adding line breaks to an InfoPath field is a bit tricky indeed. Greenant's solution works if you are using code and a rich text field, but if you are not using a rich text field (and just using a regular string field), then there is a relatively simple trick to get those newlines.  I can't find the post on this forum where I originally saw this so I'll just reproduce it here.

     Create an XML file with the following contents and add it as a secondary data source for your form (I'm also attaching the file to this message):

    <?xml version="1.0"?>

    Then, when you want to add a newline to a field, simply reference this newLine field in a concat function (you can use the Insert field or group... feature to locate it).

    The following formula would produce a value with a line break between "Hello" and "Dolly":

     concat("Hello", newLine, "Dolly")

    XPath expanded: 

    concat("Hello", xdXDocument:GetDOM("lineBreaks")/linebreaks/newLine, "Dolly")

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 04-30-2009 12:12 PM In reply to

    Okay, I see. So with this xml file it doesn't really matter where it's stored, right? As long as I can make a data connection to it should work, right?

    I'll try it now -- I'll put it on the SharePoint site that the form lives and see how it goes. I'll also report back to let you guys know how it went. :)

  • 04-30-2009 12:34 PM In reply to

    Hmmmm, I wasn't able to get this to work with my Expression Box. Here's what I did:

    Uploaded the file you provided to a Document Library on my sharepoint site:


    Created a data connection to the file:


    I then modified the Expression Box formula:


    The XPath expanded looks like this:

    concat(@RelDateA, xdXDocument:GetDOM("LineBreaks")/linebreaks/newLine, @RelDateB, xdXDocument:GetDOM("LineBreaks")/linebreaks/newLine, @RelDateC)


    Here's my result:


    Any guidance on where I may have gone wrong?

  • 04-30-2009 01:21 PM In reply to

    I tried this but with "D" in it.



    Alas, no joy... :(

  • 04-30-2009 11:24 PM In reply to

    I think the main trouble here is that Expression Boxes do not support line breaks, so you'll probably need to use a textbox.  There are a few ways to go about this.  You could create a textbox that's bound to a field in your main data source, and set its default value to be the expression you're using above.  If you don't want to have the value in your main data source, there's another slightly trickier option, so please let me know.

     Also, there's no need to access the newLine data source from SharePoint.  You can have the XML data source embedded in your form (just select "XML file" as the source when setting up the data connection, and then browse to the XML file).

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-04-2009 05:47 PM In reply to

    Hmmmm, so far I've not been able to make this work. I first added the XML files as a Data Connection (selected Receive type). I then set up a new field in my Main data source to bind a text box to. I created a text box, bound it to the new field and in the formula dialog box set up a few columns with lineBreaks betwen them but no joy...

  • 05-04-2009 09:49 PM In reply to

    Did you make sure to set the text box as a multi-line text box (in its properties)?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-05-2009 10:54 AM In reply to

    Negative Ghost Rider...

    But after applying that, it worked as described. :)

    My next question is how can I get the linebreaks to NOT appear if there's no data in the field? See this screen capture of what I'm encountering. I have date columns A-U (21 total) but would prefer only the ones that have data to display. Can this be a modification of the xml file?

    Also, when I embeded the xml data in my form it worked fine when doing Preview but after saving my work and closing things I was unable to open the form again in Design. It kept referencing the xml and not being able to find it or something (I wish I would have kept a screen shot of it). I eventually had to use an older version of the form and start again from there...

Page 1 of 2 (30 items) 1 2 Next >
Copyright © 2003-2018 Qdabra Software. All rights reserved.
View our Terms of Use.