Search code examples
c#printingobjectlistview

How to print a Objectlistview with ListViewPrinter-Class


i need to print a objectlistview and want to use the ListViewPrinter-Class for it. This is what a already did:

BrightIdeasSoftware.ListViewPrinter printer = new BrightIdeasSoftware.ListViewPrinter();
printer.AlwaysCenterListHeader = true;
printer.ListView = this.AenderungenFOLV;
printer.DocumentName = "Fuhrpark Änderungsliste";
printer.Header = "Fuhrpark Änderungsliste";
printer.DefaultPageSettings.Margins.Top = 5;
printer.DefaultPageSettings.Margins.Left = 5;
printer.DefaultPageSettings.Margins.Right = 5;
printer.IsListHeaderOnEachPage = true;
printer.Watermark = "Fuhrpark";
printer.WatermarkTransparency = 50;
printer.Footer = "Fuhrpark - " + DateTime.Now.ToString("dddd, dd.MMMM yyyy HH:mm");
printer.PrintPreview();

This is the result of the previous code: This is the result of the previous code

I want to make the List fit to the pagesize. It is always that small and wrap the ListHeader. Setting

printer.ListHeaderFormat.CanWrap = false;

isnt working. It is just making the Headertext ending with "...".

Thanks in advance.

Regards, Relax


Solution

  • I believe both "features" are no supported out of the box. Essentially, the ListViewPrinter is printing the exact representation of your ObjectListView. If your headers do not wrap in the OLV itself, its probably due to a smaller font.

    Regarding fitting the Pagesize it comes down to the same problem. The ListViewPrinter won't manipulate the OLV by itself. However, you could manually re-format the columns before printing to fit the page and reset it afterwards.

    I am doing something similar in one of my applications, because the user can dynamically choose which columns should be printed. The dialog contains a PrintPreviewControl that instantly updates the view on any changes that were made. If you change the width of a column or the whole listview, the ListViewPrinter will reflect that.