Current filter:
                                You should refresh the page.
                                Support Center
                                  • There are many applications where GridControl contains columns that are bound to fields with specific types, such as Boolean or Image. In order to display and edit these columns, there is a number of special edit settings, which provide the best way to maintain the data: CheckBox for the Boolean columns and PopupImageEdit for the Image ones. Besides, when it comes to the GridControl exporting and printing, the following questions often arise:

                                    - What should I do to show Image in the PopupImageEdit column when the grid is printed?
                                    - How to display text values instead of a checkbox in a printed grid?
                                    - Is there a way to show all MemoEdit text when printing?

                                    All these issues have a common solution approach, which is described in this article.

                                1 Solution

                                Creation Date Rating Importance Sort by

                                When some cell is being printed, its appearance is defined by DisplayTemplate defined in the cell's printing style. So, if it is necessary to change the cell's printing appearance, you should create a new control template for this cell, and set it as DisplayTemplate within a custom printing cell style. However, take into account that if you want to get completely custom data printing representation you are welcome to use our XtraReports product that offers you a powerful and flexible approach of creating custom reports.

                                For instance, if you use PopupImageEdit as an editor for some column, you may want to show images in that column's cells when printing. The idea is to put the ImageEdit control within a cell display template and bind its Source property to the cell's value.

                                <Style x:Key="ImageColumnPrintingStyle" TargetType="{x:Type dxe:PopupImageEdit}" BasedOn="{StaticResource {dxgt:TableViewThemeKey ResourceKey=DefaultPrintCellStyle}}"> <Setter Property="dxp:ExportSettings.TargetType" Value="Panel"/> <Setter Property="DisplayTemplate"> <Setter.Value> <ControlTemplate TargetType="dxe:PopupImageEdit"> <dxe:ImageEdit Source="{Binding Path=Value}" IsPrintingMode="True"/> </ControlTemplate> </Setter.Value> </Setter> </Style>

                                This xaml contains a few significant details. First, this style declaration has the TargetType and BasedOn properties specifications. A new cell printing style must be based on predefined DefaultPrintCellStyle. The TargetType property must be set to the type of an editor that is used in the column which this style will be applied to.

                                The second thing to know is that all controls that are used in this template must be adjusted for printing. Thus, any control inherited from BaseEdit must have the IsPrintingMode property set to true.

                                Every other control must be adjusted for printing via the ExportSettings attached property. Thus, it must be provided with the ExportSettings.TargetType property value. This property is defined in the xmlns:dxp="" namespace and specifies how this control should be treated by the printing subsystem.

                                For example, if you want to print TextBlock, it is necessary to specify ExportSettings.TargetType as Text, so TextBlock will be printed. If you want to set the background and foreground of some control, you should set ExportSettings.Background and ExportSettings.Foreground respectively.

                                <TextBlock Text="Textblock text" Margin="10" Foreground="Red" dxp:ExportSettings.TargetType="Text" dxp:ExportSettings.Background="White" dxp:ExportSettings.Foreground="Red" />

                                Shapes and complex controls can be exported as an Image:

                                <Ellipse Fill="Yellow" Width="15" Height="15" dxp:ExportSettings.TargetType="Image" dxp:ExportSettings.Background="Transparent" />

                                If you have some panel within a printing template you should set its ExportSettings.TargetType to Panel to let the printing subsystem process child elements.

                                <StackPanel dxp:ExportSettings.TargetType="Panel"> <TextBlock Text="Property: " Margin="2" dxp:ExportSettings.TargetType="Text"/> <TextBlock Text="Value" Margin="2" dxp:ExportSettings.TargetType="Text"/> </StackPanel>

                                If a control does not have the ExportSettings.TargetType attached property specified, it will be ignored by the printing subsystem and will be missing in the printed document. This applies to editors where the IsPrintingMode property is not set, too.

                                Finally, note that the ImageEdit Source property is simply bound to a cell's Value property from data context. So you can easily obtain the cell value.

                                Now, when the style is ready, you should only set the column's PrintCellStyle property:

                                <dxg:GridColumn FieldName="Image" PrintCellStyle="{StaticResource ImageColumnPrintingStyle}"> <dxg:GridColumn.EditSettings> <dxe:PopupImageEditSettings/> </dxg:GridColumn.EditSettings> </dxg:GridColumn>

                                Note: Every PrintCellStyle affects the appearance of a specified cell. By default, cells are stacked in a line within a default row template. If you want to completely change the printing row appearance, please refer to the How to customize the DXGrid printing appearance. article.

                                As for CheckBox, if you want to replace the standard CheckBox printing appearance with a meaningful text representation, you can place TextEdit within a cell's display template and bind its Text property to the cell's value via a converter that will return an appropriate text.

                                <local:BoolToTextConverter x:Key="BoolToTextConverter" TrueText="Avaliable" FalseText="NotAvaliable"/> <Style x:Key="CheckEditColumnPrintingStyle" TargetType="dxe:CheckEdit" BasedOn="{StaticResource {dxgt:TableViewThemeKey ResourceKey=DefaultPrintCellStyle}}"> <Style.Setters> <Setter Property="dxp:ExportSettings.TargetType" Value="Panel"/> <Setter Property="DisplayTemplate"> <Setter.Value> <ControlTemplate TargetType="dxe:CheckEdit"> <dxe:TextEdit Text="{Binding Value, Converter={StaticResource BoolToTextConverter}}"/> </ControlTemplate> </Setter.Value> </Setter> </Style.Setters> </Style>

                                Another way to accomplish this task in WPF is to define triggers within the display template, bind them to an editor's IsCheked property, and handle cell text via a trigger's setter. In this case, no single line of code behind is required.

                                <ControlTemplate TargetType="dxe:CheckEdit"> <dxe:TextEdit Name="Text"/> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter Property="Text" Value="Avaliable" TargetName="Text"/> </Trigger> <Trigger Property="IsChecked" Value="False"> <Setter Property="Text" Value="Not avaliable" TargetName="Text"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate>

                                Note: There are no triggers in Silverlight. So, this approach can be used in WPF applications only.

                                If you use a multi-line editor in some cells, such as MemoEdit, it is necessary to enable text wrap in the editor to render the cells during printing. The solution is similar to the one described above. You can place TextEdit into a cell's display template, bind its Text property to the cell's value, and set the editor's TextWrapping property to Wrap.

                                <Style x:Key="MemoColumnPrintingStyle" TargetType="dxe:MemoEdit" BasedOn="{StaticResource {dxgt:TableViewThemeKey ResourceKey=DefaultPrintCellStyle}}"> <Style.Setters> <Setter Property="dxp:ExportSettings.TargetType" Value="Panel"/> <Setter Property="DisplayTemplate"> <Setter.Value> <ControlTemplate TargetType="dxe:MemoEdit"> <dxe:TextEdit Text="{Binding Value}" IsPrintingMode="True" TextWrapping="Wrap"/> </ControlTemplate> </Setter.Value> </Setter> </Style.Setters> </Style>

                                You can find a sample project that implements all these solutions in the How to use the PrintCellStyle property to customize cell's printing appearance Code Central example below.

                                If you need additional product information, write to us at or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2017 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners