This is a migrated thread and some comments may be shown as answers.

Merging fields with multiline content ignores line breaks?

6 Answers 136 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 12 Mar 2013, 05:56 PM
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



6 Answers, 1 is accepted

Sort by
0
Mihail
Telerik team
answered on 15 Mar 2013, 04:15 PM
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.

0
Rob
Top achievements
Rank 1
answered on 18 Mar 2013, 02:41 PM
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));
         }
      }
         
   }
 
}



0
Iva Toteva
Telerik team
answered on 21 Mar 2013, 02:52 PM
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.

0
Sergi
Top achievements
Rank 1
answered on 07 May 2013, 02:52 PM
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
0
Iva Toteva
Telerik team
answered on 10 May 2013, 05:31 PM
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.

0
Lawrence
Top achievements
Rank 2
Iron
answered on 22 Aug 2013, 06:24 PM
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;
}
Tags
RichTextBox
Asked by
Rob
Top achievements
Rank 1
Answers by
Mihail
Telerik team
Rob
Top achievements
Rank 1
Iva Toteva
Telerik team
Sergi
Top achievements
Rank 1
Lawrence
Top achievements
Rank 2
Iron
Share this question
or