KB Article T680332
Visible to All Users

WinForms - How to hide a mail merge template from the ShowInDocument Action

Scenario
There are custom mail merge templates for the Employee class. Each template relates to a specific department. When you select an employee from the Sales department, the ShowInDocument Action displays only corresponding templates.

Solution

The Solution is available starting with version 18.1.7.
1.  In the YourSolutionName.Module project, extend the DevExpress.Persistent.BaseImpl.RichTextMailMergeData class (or DevExpress.Persistent.BaseImpl.EF.RichTextMailMergeData if you use Entity Framework) with the Department property and override the GetAdditionalMailMergeInfo method to return the Department instance.

C#
using DevExpress.Persistent.BaseImpl; using DevExpress.Xpo; namespace FilterMailMergeTemplateExample.Module.BusinessObjects { public class CustomMailMergeData : RichTextMailMergeData { public CustomMailMergeData(Session session) : base(session) { } public Department Department { get { return GetPropertyValue<Department>(nameof(Department)); } set { SetPropertyValue(nameof(Department), value); } } public override object GetAdditionalMailMergeInfo() { return Department; } } }

2. Specify the CustomMailMergeData type as the RichTextMailMergeDataType option as described at Mail Merge.
3.1  In the YourSolutionName.Blazor.Server/YourSolutionName.Win projects, inherit the ShowInDocumentController class and override the FilterActionItems method as follows:

Blazor

C#
using DevExpress.ExpressApp.Actions; using dxTestSolution.Module.BusinessObjects; using DevExpress.ExpressApp.Office; using DevExpress.ExpressApp.Office.Blazor.Controllers; using dxT1218062.Module.BusinessObjects; namespace dxTestSolution.Blazor.Server.Controllers; public class CustomShowInDocumentController : BlazorShowInDocumentController { public CustomShowInDocumentController() : base() { } protected override void FilterActionItems(IList<ChoiceActionItem> items) { base.FilterActionItems(items); if (View.ObjectTypeInfo.Type == typeof(ApplicationUser)) { foreach (ChoiceActionItem item in items) { Department department = ((MailMergeDataInfo)item.Data).AdditionalMailMergeInfo as Department; if (department != null) { item.Active["Filter"] = View.SelectedObjects.OfType<ApplicationUser>().All(employee => employee.Department != null && employee.Department.Name == department.Name); } } } } }

WinForms

C#
using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.Office.Win; using DevExpress.ExpressApp.Office; using FilterMailMergeTemplateExample.Module.BusinessObjects; using System.Collections.Generic; using System.Linq; namespace FilterMailMergeTemplateExample.Module.Win.Controllers { public class CustomShowInDocumentController : ShowInDocumentController { public CustomShowInDocumentController() : base() { } protected override void FilterActionItems(IList<ChoiceActionItem> items) { base.FilterActionItems(items); if(View.ObjectTypeInfo.Type == typeof(Employee)) { foreach(ChoiceActionItem item in items) { Department department = ((MailMergeDataInfo)item.Data).AdditionalMailMergeInfo as Department; if(department != null) { item.Active["Filter"] = View.SelectedObjects.OfType<Employee>().All(employee => employee.Department != null && employee.Department.Name == department.Name); } } } } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.