Articles in this section
Category / Section

How to Print the data in Pivot Grid

2 mins read

Printing support is now available in PivotGrid control. By using the print button one can print the pivot grid as it is in the output window and also it is possible to customize the pivot grid before printing by adding header and footer and also removing the grouping bar.

XAML

<GroupBox Header="Properties" Grid.Row="2" VerticalAlignment="Top" FontFamily="Calibri" FontSize="14" FontStretch="Condensed" BorderThickness="1" BorderBrush="DarkGray" Margin="5,0" Height="115">

                <StackPanel Orientation="Vertical">

                    <CheckBox x:Name="chkHeader" Content="Header" Margin="10 10 10 5" Width="100" IsChecked="{Binding IsHeaderChecked, Mode=TwoWay}"

                             Command="{Binding HeaderCommand}" CommandParameter="{Binding Source={StaticResource HeaderTemplate}}" />

                    <CheckBox x:Name="chkFooter" Content="Footer" Margin="10 5 10 5" Width="100" IsChecked="{Binding IsFooterChecked, Mode=TwoWay}"

                             Command="{Binding FooterCommand}" CommandParameter="{Binding Source={StaticResource FooterTemplate}}" />

                    <CheckBox x:Name="chkGroupBar" Content="Grouping Bar" Margin="10 5 10 5" Width="100" IsChecked="{Binding Path=ShowGroupingBar, ElementName=pivotGrid1, Mode=TwoWay}" />

                </StackPanel>

            </GroupBox>

            <Button Grid.Row="2" Height="33" HorizontalAlignment="Left" Margin="52,121,0,0" Name="button1" VerticalAlignment="Top" Width="100" Content="Print" Command="{Binding PrintCommand}" CommandParameter="{Binding ElementName=pivotGrid1}"/>

 

C#

public class PrintCommand:ICommand

    {

        private readonly Action<object> _execute;

        private readonly Predicate<object> _canExecute;

 

        /// <summary>

        /// Default constructor to execute an action.

        /// </summary>

        /// <param name="execute">action to execute.</param>

        public PrintCommand(Action<object> execute)

            : this(execute, null)

        {

        }

 

        /// <summary>

        /// Constructor to execute an action only on approval.

        /// </summary>

        /// <param name="execute">action to execute.</param>

        /// <param name="canExecute">whether to execute or not</param>

        public PrintCommand(Action<object> execute, Predicate<object> canExecute)

        {

            if (execute == null)

                throw new ArgumentNullException("execute");

            _execute = execute;

            _canExecute = canExecute;

        }

 

        /// <summary>

        /// Gets whether to execute the action or not.

        /// </summary>

        /// <param name="parameter">element that undergoes action.</param>

        /// <returns>a boolean value</returns>

        public bool CanExecute(object parameter)

        {

            return _canExecute == null ? true : _canExecute(parameter);

        }

 

        /// <summary>

        /// An event that determines whether the proposed execution can be changed.

        /// </summary>

        public event EventHandler CanExecuteChanged

        {

            add { CommandManager.RequerySuggested += value; }

            remove { CommandManager.RequerySuggested -= value; }

        }

 

        /// <summary>

        /// A method to execute action.

        /// </summary>

        /// <param name="parameter">object to incur action.</param>

        public void Execute(object parameter)

        {

            _execute(parameter);

        }

    }

}

 

 

 

C:\Users\labuser\Dropbox\Screenshots\Screenshot 2014-05-26 17.05.20.png

 

C:\Users\labuser\Dropbox\Screenshots\Screenshot 2014-05-26 16.19.03.png

Figure: pivot Grid with Printing Support

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied