Hello,I would like to make an impression of the data of a XamDataGrid but only certain fields and my problem is that, when I launch the printing, all the fields of the DataSource are printed.I would like to be able to specify that only certain fields in particular should be printed, and without changing the visibility of the fields in the XamDataGrid.For example, I have 5 fields, Col1, Col2, Col3, Col4 and Col5 that appear in the XamDataGrid and I only want to print Col2 and Col3 and no others. How can I do?I can't find a solution, I tried:
private void BtnImprimer_Click(object sender, RoutedEventArgs e) { Report report = new Report(); EmbeddedVisualReportSection section = new EmbeddedVisualReportSection(dtg); section.PaginationStarting += new EventHandler<EmbeddedVisualPaginationEventArgs>(Section_PaginationStarting); report.Sections.Add(section); report.ReportSettings.PageOrientation = PageOrientation.Landscape; report.Print(); section.PaginationStarting -= Section_PaginationStarting; } private void Section_PaginationStarting(object sender, EmbeddedVisualPaginationEventArgs e) { DataPresenterBase presenter = e.VisualPaginator as DataPresenterBase; if (presenter != null) { presenter.FieldLayoutInitialized += Presenter_FieldLayoutInitialized; presenter.FieldLayoutInitializing += Presenter_FieldLayoutInitializing; } } private void Presenter_FieldLayoutInitializing(object sender, FieldLayoutInitializingEventArgs e) { e.FieldLayout.Fields.Clear(); e.FieldLayout.Settings.AutoGenerateFields = false; _GestionnaireConfigListe.InitialiserChampDatagridImpression(e.FieldLayout); }
But it no longer finds the fields to print.And with :
private void Presenter_FieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e) { e.FieldLayout.Fields.Clear(); e.FieldLayout.Settings.AutoGenerateFields = false; _GestionnaireConfigListe.InitialiserChampDatagrid(e.FieldLayout); }
it prints empty pages to me.Is it possible to choose the fields that we want to print?
I use Infragistics 18.2
Hello,
I am glad that you managed to achieve your requirement.
Please do not hesitate to let me know if you have any further questions on this matter.
Regards,Teodosia HristodorovaAssociate Software Developer
Thank you for your attention.I solved my problem with your first answer.In fact, what posed problem is that I did not use the visibility of the fields, I only generated the fields which I needed to fill the XamDataGrid, because each user has his own profile to display only the fields that 'he wants, while we must generate them all and collapse those that we do not want to display. In this way, printing takes only the displayed fields.But if we do not generate them, as I did, they are all still taken when printing. Surely because the report must be based directly on the DataSource to retrieve the fields and apply the parameters of the FieldLayout, which has no Collapsed fields, and suddenly we find all the fields.
After further research, I determined that your approach could be applied if you the PaginationEnded event is handled as well.
I have created a small sample using PaginationStarting and PaginationEnded events. For the purposes of the example, I printed only the fields which indexes are odd numbers.
Attached you will find my sample for your reference. By modifying the FieldLayoutInitialized you will be able to achieve the desired behavior. Please test it on your side and let me know how it behaves.
Let me know if I may be of any further assistance.
Sincerely,
Teodosia Hristodorova
Associate Software Developer
5543.XamDataGrid_Print_Some_Fields.zip
After an investigation, I found this forum thread where a similar question has been discussed. According to this thread the printing engine prints a visual element. That means that it will print all visible fields of XamDataGrid.
A workaround I can suggest to create an additional grid where all required fields would be added and after that to print this grid.
If you require any further assistance on the matter, please let me know.