Merging fields with multiline content ignores line breaks?

7 posts, 0 answers
  1. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 12 Mar 2013 Link to this post

    Hello,

    I am using the merge fields feature of the rich text box.  When I attempt to merge data that has line breaks, they are ignored.  Is there a way to make this work properly?

    Thanks,
    Rob



  2. Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 15 Mar 2013 Link to this post

    Hello Rob,
     
    We couldn't reproduce the described behavior. Can you give us more details on your scenario or even better - open a support ticket with a simple working demo project illustrating the issue.

    All the best,
    Mihail
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 18 Mar 2013 Link to this post

    Hello Mihail,

    I think the problem has something to do with inserting the field with FieldDisplayMode = "Result" instead of "Code".  Please see the following project which demonstrates the two methods:

    <UserControl
      x:Class="SilverlightApplication70.MainPage"
    >
     
    <Grid x:Name="LayoutRoot" Background="White">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="1*" />
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*" />
        <ColumnDefinition Width="1*" />
      </Grid.ColumnDefinitions>
      <!-- Data -->
      <ListBox Grid.Row="0" Grid.ColumnSpan="2" ItemsSource="{Binding Items}">
        <ListBox.ItemTemplate>
          <DataTemplate>
            <TextBox Text="{Binding TextProperty, Mode=TwoWay}" AcceptsReturn="True" />
          </DataTemplate>
        </ListBox.ItemTemplate>
      </ListBox>
      <!-- Insert As Code And Then Merge -->
      <StackPanel Grid.Row="1" Grid.Column="0">
        <Button Content="Insert Merge Field As Code" Click="btn_InsertAsCode" />
        <Button Content="Perform Merge" Click="btn_Merge" />
        <telerik:RadRichTextBox x:Name="rtb1" />
        <telerik:RadRichTextBox x:Name="rtb2" />
      </StackPanel>
      <!-- Insert Directly As Result -->
      <StackPanel Grid.Row="1" Grid.Column="1">
        <Button Content="Insert Merge Field As Result" Click="btn_InsertAsResult" />
        <telerik:RadRichTextBox x:Name="rtb3" />
      </StackPanel>
    </Grid>
    </UserControl>


    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Windows;
    using System.Windows.Controls;
    using Telerik.Windows.Documents.Model;
     
    namespace SilverlightApplication70
    {
       public partial class MainPage : UserControl
       {
             
          public MyDataContext dc = new MyDataContext();
             
          public MainPage()
          {
             InitializeComponent();
             dc.Items = new List<MyDataObject>()
             {
                new MyDataObject()
                {
                   TextProperty = "START1\nLorem ipsum dolor sit amet, consectetur adipiscing elit.\nMauris sit amet risus elit.\nDonec ullamcorper aliquam elit commodo accumsan.\nEND1"
                },
                new MyDataObject()
                {
                   TextProperty = "START2\nVivamus dapibus varius augue non rutrum.\nMorbi in iaculis mauris.\nEND2"
                },
                new MyDataObject()
                {
                   TextProperty = "START3\nDonec congue sagittis libero, commodo imperdiet leo tempus a.\nEND3"
                },
             };
             this.DataContext = dc;
             this.rtb1.Document.MailMergeDataSource.ItemsSource = dc.Items;
             this.rtb3.Document.MailMergeDataSource.ItemsSource = dc.Items;
          }
     
          private void btn_InsertAsCode(object sender, RoutedEventArgs e)
          {
             this.rtb1.ActiveDocumentEditor.InsertField
             (
                new MergeField()
                {
                   PropertyPath = "TextProperty"
                },
                FieldDisplayMode.Code
             );
          }
     
          private void btn_Merge(object sender, RoutedEventArgs e)
          {
             this.rtb2.Document = this.rtb1.MailMergeCurrentRecord();
          }
     
          private void btn_InsertAsResult(object sender, RoutedEventArgs e)
          {
             this.rtb3.ActiveDocumentEditor.InsertField
             (
                new MergeField()
                {
                   PropertyPath = "TextProperty"
                },
                FieldDisplayMode.Result
             );
          }
       }
     
     
       public class MyDataObject
       {
          public string TextProperty
          {
             get;
             set;
          }
       }
     
       public class MyDataContext : INotifyPropertyChanged
       {
          private List<MyDataObject> _Items;  
          public List<MyDataObject> Items
          {
             get
             {
                return _Items;
             }
             set
             {
                _Items = value;
                RaisePropertyChanged("Items");
             }
          }
     
          public event PropertyChangedEventHandler PropertyChanged;
          protected void RaisePropertyChanged(string propertyName)
          {
             var propertyChanged = PropertyChanged;
     
             if ((propertyChanged != null))
             {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
             }
          }
             
       }
     
    }



  5. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 21 Mar 2013 Link to this post

    Hello Rob,

    Actually the problem is that you have new lines (paragraphs) and not line breaks. Multiple paragraphs in the result of a mail merge field are not thoroughly supported. We will revise the logic and try to implement it for the upcoming service pack or soon after that.

    All the best,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Sergi
    Sergi avatar
    1 posts
    Member since:
    May 2013

    Posted 07 May 2013 Link to this post

    Hello Iva,

    I'm using the merge fields in RichTextBox also, I try to merge data with \n, \n\r, CHR(13), CHR(10) and <br> but when I try merge the document is still merged in one line. What can I do to have a multiline merge field?

    Thanks, 
    Sergi
  7. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 10 May 2013 Link to this post

    Hi Sergi,

    This improvement has not been implemented yet. You can check the solution with custom merge field included in this forum thread. The first example is for WPF, but the last post includes an example for Silverlight.

    Regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Lawrence
    Lawrence avatar
    10 posts
    Member since:
    Jul 2013

    Posted 22 Aug 2013 Link to this post

    This is a bit of a "hack/ghetto" solution, and I have only verified it with WPF.  I ran across this article that described a special character causing a line break.  In my case, I have an Address1 and Address2 fields.  If Address2 is not null or empty, then I want to show it on my merge document, otherwise don't.  If I use a separate merge field, I would have an empty line, not good.

    The special character is "¬".
    const string LineBreakSymbol = "¬";
     
    if (!string.IsNullOrWhiteSpace(this.Address2))
    {
        this.AddressCombined = string.Format("{0}{1}{2}", this.Address1, LineBreakSymbol, this.address2);
    }
    else
    {
        this.AddressCombined = this.Address1;
    }
Back to Top
DevCraft banner