We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfDataGrid Printing Header Template with Costum Elements

Thread ID:

Created:

Updated:

Platform:

Replies:

129616 Mar 24,2017 12:04 PM UTC Mar 30,2017 05:16 PM UTC WPF 3
loading
Tags: SfDataGrid
Amine Laïeb
Asked On March 24, 2017 12:04 PM UTC

Greetings,
     I have a Grid that contains a SfDataGrid and a ComboBox, I'm trying to Print the SfDataGrid and in the Header the SelectedItem of the ComboBox knowing that it is bound to a database (the items of the ComboBox change constantly), How can it Print the both in the same Page ?

Jai Ganesh S [Syncfusion]
Replied On March 28, 2017 12:44 AM UTC

Hi Amine, 
You can achieve your requirement for printing the both SfDataGrid and ComboBox in same page and the ComboBox SelectedITem as the header of SfDataGrid by using the PrintPageHeaderTemplate. The header text can be shown by using visual brush and text block. 
Using Visualbrush: 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
 
    VisualBrush visualbrush = new VisualBrush(); 
    visualbrush.Visual = stackpanel; 
             
    FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid)); 
    FrameworkElementFactory borderelement = new FrameworkElementFactory(typeof(Border)); 
    borderelement.SetValue(Border.BackgroundProperty, visualbrush); 
    borderelement.SetValue(Border.HeightProperty, 75.0); 
    borderelement.SetValue(Border.WidthProperty, 1020.0); 
    borderelement.SetValue(Border.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); 
    borderelement.SetValue(Border.VerticalAlignmentProperty, VerticalAlignment.Stretch); 
 
    grid.AppendChild(borderelement); 
 
 
    datatemplate.VisualTree = grid; 
 
    this.datagrid.PrintSettings.AllowRepeatHeaders = false; 
    datagrid.PrintSettings.PrintPageHeaderTemplate = datatemplate; 
    datagrid.PrintSettings.PrintPageHeaderHeight = 55; 
 
    this.datagrid.ShowPrintPreview(); 
} 
 
 
using TextBlock: 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    DataTemplate datatemplate = new DataTemplate(); 
             
    TextBlock textblock = new TextBlock(); 
    textblock.Text = combobox.SelectedItem.ToString(); 
 
    FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid)); 
            
    FrameworkElementFactory textblockfactory = new FrameworkElementFactory(typeof(TextBlock)); 
 
 
    textblockfactory.SetValue(TextBlock.TextProperty, textblock.Text); 
    textblockfactory.SetValue(TextBlock.BackgroundProperty, Brushes.Gray); 
    grid.AppendChild(textblockfactory); 
 
    datatemplate.VisualTree = grid; 
 
 
    this.datagrid.PrintSettings.AllowRepeatHeaders = false; 
    datagrid.PrintSettings.PrintPageHeaderTemplate = datatemplate; 
    datagrid.PrintSettings.PrintPageHeaderHeight = 25; 
 
    this.datagrid.ShowPrintPreview(); 
} 
 
Sample: 
 
Reference: 
Regards, 
Jai Ganesh S 


Amine Laïeb
Replied On March 29, 2017 10:20 AM UTC

Thank you very much works perfectly

Muthukumar Kalyanasundaram [Syncfusion]
Replied On March 30, 2017 05:16 PM UTC

Hi Amine, 
 
You are welcome. Please let us know if you need any other assistance. 
 
Regards, 
Muthukumar K 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;