Search code examples
vb.netgridviewdevexpressdevexpress-windows-ui

Export to Excel all details from Master Detail GridView in Devexpress


I have 2 GridViews that have a master-detail relationship between them. Right now, when I have one row selected I'm able to export to excel the Gridview's detail by doing this:

GridView2.ExportToXlsx("OneMasterDetail.xlsx")

But what I want to do is export all the possible details from the master GridViews. I've tried the following but it just exports the master-detail that is currently selected.

GridView2.OptionsPrint.PrintDetails = True
GridView2.OptionsPrint.ExpandAllDetails = True
GridView2.ExportToXlsx("AllMasterDetail.xlsx")

Just to be sure I'm being clear. Let's say I have a Master GridView that has brands of cars, and the detail GridView that gives you the car colors available for that brand of car. The final Excel would have all the car brands with all their available colors.


Solution

  • I had the same issue. It seems the Grid View's native export function is a little too primitive to pick up the various options and does more of a straight dump. If you want to accomplish what you seek, you need to use the DevExpress XtraPrinting library:

    using DevExpress.XtraPrinting;
    

    I don't know VB.net, but I am hopeful you can translate my C# into what you need. This will achieve the result you are after:

    using (PrintableComponentLink link = new PrintableComponentLink(new PrintingSystem()))
    {
        link.Component = GridControl2;
        link.CreateDocument(link.PrintingSystem);
        link.ExportToXlsx("AllMasterDetail.xlsx");
    }
    

    This is also necessary if, for example, you want the output as landscape rather than portrait.

    --edit-- screen shots

    UI:

    enter image description here

    Exported Spreadsheet:

    enter image description here