SfDataGrid Printing Header Template with Costum Elements
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 ?
SIGN IN To post a reply.
3 Replies
JG
Jai Ganesh S
Syncfusion Team
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(); } |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SfGridDemo-1773156367.zip
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
AL
Amine Laïeb
March 29, 2017 10:20 AM UTC
Thank you very much works perfectly
MK
Muthukumar Kalyanasundaram
Syncfusion Team
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
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
AL Amine Laïeb
- Mar 24, 2017 12:04 PM UTC
- Mar 30, 2017 05:16 PM UTC