Question

I want to enable user to move things around on a devexpress print preview and print it only after it is done. If it is possible, could I get some directions where I can start looking? (I will not have the time to look into the whole documentation, what may sound lazy, but devx is kinda huge for the short time I have.)

Was it helpful?

Solution

I don't think you could do this on the Print preview directly, but what you could do is provide a button which launches the XtraReports Designer and pass in the layout from your currently displayed document. When the user has finished editing then you can reload the document in the print preview, loading its new layout as required. You may need to customize the designer heavily to remove various options restricting the user to only editing certain aspects - you can hide much of the functionality including data source, component tray etc:

designer video

designer documentation

hide options in designer

if(EditLayout(document))
   RefreshDocument();

public static bool EditLayout(XtraReport document)
{
        using (var designer = new XRDesignRibbonForm())
        {
            designer.OpenReport(document);
            XRDesignPanel activePanel = designer.ActiveDesignPanel;
            activePanel.AddCommandHandler(new DesignerCommandHandler(activePanel));
            HideDesignerOptions(activePanel);
            designer.ShowDialog();
            changesMade = activePanel.Tag != null && (DialogResult)activePanel.Tag == DialogResult.Yes;  //set this tag in your DesignerCommandHandler
            activePanel.CloseReport();
        }
        return changesMade;
}

Finally, some utility methods for changing a document/reports layout:

    internal static byte[] GetLayoutData(this XtraReport report)
    {
        using (MemoryStream mem = new MemoryStream())
        {
            report.SaveLayoutToXml(mem);
            return mem.ToArray();
        }
    }

    internal static void SetLayoutData(this XtraReport report, byte[] data)
    {
        using (var mem = new MemoryStream(data))
        {
            report.LoadLayoutFromXml(mem);
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top