For example, rather than having the data flattened out, due to the large number of tables from which to fetch the data and different types of summary records required, it would be simpler to be able to bind to multiple data sources.
As a simplistic example, let's say we're displaying Customer information (FirstName, LastName, Address info which is still linked , etc) from one data source, and then order information from another (LastOrderAmount, DateLastOrdered, YTDOrderAmount, NumberOfOrdersPlaced, etc.).
Add to this another 10 different datasources such as the order information described above.
To make this into a single data source would be quite a task, difficult to maintain, and possibly a performance hog. Having multiple datasources would simplify and mitigate these concerns.
Is this feasable?
3 Answers, 1 is accepted
Actually mail merge fields support property path syntax; it's only the UI that has a limitation for adding merge fields with complex paths. You can, however, customize it to show buttons for adding such fields:
- Remove the binding of the button to the InsertMergeFieldEmptyCommand. In the default RadRichTextBoxRibbonUI, it is:
<
telerikRibbonBar:RadRibbonDropDownButton
CollapseToMedium
=
"WhenGroupIsMedium"
LargeImage
=
"/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/32/InsertMergeField.png"
telerik:RadRichTextBoxRibbonUI.RichTextCommand
=
"{Binding Path=InsertMergeFieldEmptyCommand}"
Size
=
"Large"
Text
=
"Insert Merge Field"
/>
Instead, give the button a name like this, so that you can refer to that button in code behind:<
telerikRibbonBar:RadRibbonDropDownButton
CollapseToMedium
=
"WhenGroupIsMedium"
LargeImage
=
"/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/32/InsertMergeField.png"
Size
=
"Large"
Text
=
"Insert Merge Field"
x:Name
=
"insertMergeFieldButton"
/>
- Then, you can keep the column names which you wish to use as property paths for the merge fields in a property. Here, if needed, you can also use reflection to load the data source items properties.
string
[] ColumnNames =
new
string
[]{
"Name"
,
"Age"
,
"Address[0].Country"
,
"Address[1].Country"
};
After that you can invoke the following method with a parameter this.insertMergeFieldButton:private
void
AddMergeFieldsInDropDownContent(RadRibbonDropDownButton radRibbonDropDownButton)
{
StackPanel stackPanel =
new
StackPanel();
foreach
(
string
fieldName
in
this
.ColumnNames)
{
RadRibbonButton fieldButton =
new
RadRibbonButton()
{
Text = fieldName,
Size = ButtonSize.Medium,
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalContentAlignment = HorizontalAlignment.Left
};
fieldButton.Command =
this
.editor.Commands.InsertFieldCommand;
fieldButton.CommandParameter =
new
MergeField() { PropertyPath = fieldName };
stackPanel.Children.Add(fieldButton);
}
stackPanel.Width = 140;
radRibbonDropDownButton.DropDownContent = stackPanel;
}
If the data items are unrelated, your can create 'mixed' collection and set it as mail merge data source, for example:
this
.radRichTextBox.Document.MailMergeDataSource.ItemsSource =
from c
in
Clients
from o
in
Orders
select
new
{
FirstName = e.FirstName,
Quantity = o.Quantity
};
Don't hesitate to contact us if you have other questions.
Best wishes,
Boby
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
Hi,
I want to share the following solution and request this feature to be added to the Telerik in the near future.
I have a class which has many properties, but not all properties should be displayed in the Mail Merge. I followed Boby's example to display only selected fields. But instead of defining an array of strings for properties I created an Attribute class and defined it in my binded class itself.
public class MailMergeAttribute : Attribute
{
}
now, in my class I can define this Attribute for the properties I want to show up in the Mail Merge dropdown button. Then I have created a static property that return only properties that have MailMergeAttribute.
public class Person
{
[MailMergeAttribute]
public int PropInMailMerge1{ get; set; }
[MailMergeAttribute]
public string PropInMailMerge2{ get; set; }
public int PropNotInMailMerge{ get; set; }
public string PropNotInMailMerge2{ get; set; }
public static List<
String
> GetMailMergeFields()
{
var props = from p in typeof(PatientNotification).GetProperties()
let attr = p.GetCustomAttributes(typeof(MailMergeAttribute), true)
where attr.Length == 1
select new { Property = p, Attribute = attr.First() as MailMergeAttribute };
List<
string
> propsNames = new List<
string
>();
foreach (var prop in props)
{
propsNames.Add(prop.Property.Name);
}
return propsNames;
}
}
Now, in Boby's example, replace this line
foreach
(
string
fieldName
in
this
.ColumnNames)
with this
foreach
(
string
fieldName
in
Person
.GetMailMergeFields())
And you have it.
I would like to request from Telerik to define their own Attribute class and use this class to select which properties should show up in the Mail Merge dropdown. In addition, maybe you can add DisplayName, Order and Group properties to this Attribute class. DisplayName would allow developers to specify the name that should be displayed in the list. For example, property name could be FirstName, but in the list it is displayed as "First Name". Order would define in which order fields should show up in the InsertMailMerge dropdown. Group would allow to group attributes into a sub-menu. In case there are too many properties to be displayed in the list, some properties can be grouped under the sub-menu.
Alternatively, this class can be created with a property "bool DoNotDisplay". If developer did not specify this attribute, then the field is added as it is working now. But if you define attribute with DoNotDisplay=true, then you do not show this property in the InsertMailMerge dropdown. This way, developers don't have to add this attribute to all fields.
Thanks,
Michael
Thank you for sharing the code here, as it may help others facing the same problem. Due to the existence of relatively easy way to customize the default UI, however, for now we are not planning to implement such behavior in the control.
We have added points to your account for the suggestion. Don't hesitate to contact us if you have other questions.
Regards,
Boby
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>