I'm using the code in the KB article to print the content of a winultragrid, but the columns are extending beyond the page. I've tried calling the PerformAutoResize() function on each column but even then it causes the columns to get cutoff by the margins, and in some cases the text within the columns gets cutoff as well. What can I do to have the grid autofit to the width of the page?
You could do this:
private void ultraGrid1_InitializePrintPreview(object sender, CancelablePrintPreviewEventArgs e) { e.DefaultLogicalPageLayoutInfo.FitWidthToPages = 1; }
You could do the same thing in the InitializePrint event, too.
I am having a similar problem. I am handling both the InitializePrint and InitializePrintPreview events, the code in both looks like:
e.PrintDocument.DefaultPageSettings.Margins.Top = e.PrintDocument.DefaultPageSettings.HardMarginY
e.PrintDocument.DefaultPageSettings.Margins.Left = e.PrintDocument.DefaultPageSettings.HardMarginX
'e.PrintDocument.DefaultPageSettings.Margins.Right = e.PrintDocument.DefaultPageSettings.HardMarginX
'e.PrintDocument.DefaultPageSettings.Margins.Bottom = e.PrintDocument.DefaultPageSettings.HardMarginY
e.DefaultLogicalPageLayoutInfo.FitWidthToPages = 1
With this code the grid scales correctly to one page wide but has a large right and bottom margin on the printed page. If I uncomment the two lines that set the right and bottom margin's, the grid flies off the side of the page.
Very frustrating :(