简体   繁体   中英

Using DevExpress XtraPrint to print the data in a GridControl with two associated GridViews

I am currently programming within Visual Studio 2010 using VB.Net and DevExpress V10.2 Winforms. I currently have a DevExpress GridControl that contains two DevExpress GridViews. So there is the main view and the subgrid (similar to the DevExpress demo for Master-Detail Grids - example with WinForms and better view with ASPxGridView ). Currently the data for the grid is fetched into a DataSet:

 If myDataSet.Tables.Count > 0 Then
       myDataSet.Relations.Add("Details", myDataSet.Tables(0).Columns("id"),  myDataSet.Tables(1).Columns("id"))
       myGridControl.DataSource = myDataSet.Tables(0)
       myGridControl.LevelTree.Nodes.Add("Details", mySecondGridView)
 End If

What I want to do is generate a report that displays what the user is currently seeing in the gridControl. For example if the user filters or sorts the data or changes the column size or visibility this will be reflected in the report they generate.

Currently to generate the report I added the PrintingSystem, to the designer, and then within the PrintingSystem Links collection I added a PrintableComponentList. The PrintableComponentList.component was set to my gridcontrol. Within my code, when the Print Grid button is pressed, I call:

PrintableComponentLink1.CreateDocument()
PrintableComponentLink1.ShowPreview()

This prints a report that looks good. The columns are represented correctly and if the data is grouped, etc the report reflects this. The issue I have with this is it doesn't show the subgrid, the second gridview, even it I expand all or some of the grid before previewing the report. I even decided to ignore the printing system and instead tried printing right from the gridControl with:

myGridControl.ShowPrintPreview() 

but this also showed the first gridView and not the second GridView.

How am I supposed to showcase both the GridViews that the user currently sees within the one GridControl?

Try the following code.

CompositeLink composLink = new CompositeLink(new PrintingSystem());

PrintableComponentLink pcLink1 = new PrintableComponentLink();
PrintableComponentLink pcLink2 = new PrintableComponentLink();

pcLink1.Component = this.gridControl1;
pcLink2.Component = this.gridControl2;

composLink.Links.Add(pcLink1);
composLink.Links.Add(pcLink2);

composLink.ShowPreview();

To see the second GridView go into the Desginer for the GridControl. Once there go down the left side of the options on the left (under Main and Appearance) to the Printing options. Under Printer Settings I checked off Options.Details and Behavior.All Details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM