Hi,
When I use UltraGridPrintDocument to print a grid the grid is printed inside a border (see attached image). Is there anyway to get rid of this?
It doesn't appear in the PDF when using UltraGridDocumentExporter, which is what I'm trying to achieve when printing.
Kind regards,
Nathan
Hello Nathan,
There is a possibility of removing page border when printing with UltraGridPrintDocument using the BorderStyle property off its Page object. You can set UIElementBorderStyle.None to this property in order to remove the border. For example you can do something like this:
/ the page property is the section representing the // entire renderable area of the page. you can assign // a border around the margin area this.ultraPrintDocument1.Page.BorderStyle = UIElementBorderStyle.None;
Please let me know if I may be of further assistance.
Sincerely,Sahaja KokkalagaddaAssociate Software Developer
Hi Sahaja,
It doesn't seem to work. I'm using 2016.2.
My code is as follows:
Public Sub ExportGridToPrinter(ByVal grid1 As UltraGrid, ByVal grid2 As UltraGrid, ByVal contactName As String) Dim ultraGridExcelExporter1 As New UltraGridPrintDocument ultraGridExcelExporter1.Grid = grid1 ultraGridExcelExporter1.Page.BorderStyle = UIElementBorderStyle.None grid1.DisplayLayout.Rows.ExpandAll(True) ultraGridExcelExporter1.Header.TextLeft = "Share Holding Statement for " & contactName _ & ControlChars.CrLf & ControlChars.CrLf & "Date of Statement: " & DateTime.Today.ToLongDateString() ultraGridExcelExporter1.Header.Height = 80 ultraGridExcelExporter1.Header.Appearance.FontData.Bold = DefaultableBoolean.True ultraGridExcelExporter1.Header.Appearance.FontData.SizeInPoints = 12 ultraGridExcelExporter1.Print() End Sub
Try setting UIElementBorderStyle.None to BorderStyle property of the Grid's PrintLayout in order to remove the Grid Border from printed document. You can set this property in InitializePrint event of the Grid. For example:
private void UltraGrid1_InitializePrint(object sender, CancelablePrintEventArgs e) { e.PrintLayout.BorderStyle = UIElementBorderStyle.None; }
That doesn't work either. Here's the code.
Public Sub ExportGridToPrinter(ByVal grid1 As UltraGrid, ByVal grid2 As UltraGrid, ByVal contactName As String) Dim ultraGridExcelExporter1 As New UltraGridPrintDocument Try AddHandler grid1.InitializePrint, AddressOf grid_InitializePrint ultraGridExcelExporter1.Grid = grid1 grid1.DisplayLayout.Rows.ExpandAll(True) ultraGridExcelExporter1.Header.TextLeft = "Share Holding Statement for " & contactName _ & ControlChars.CrLf & ControlChars.CrLf & "Date of Statement: " & DateTime.Today.ToLongDateString() ultraGridExcelExporter1.Header.Height = 80 ultraGridExcelExporter1.Header.Appearance.FontData.Bold = DefaultableBoolean.True ultraGridExcelExporter1.Header.Appearance.FontData.SizeInPoints = 12 ultraGridExcelExporter1.Print() Catch Throw Finally AddHandler grid1.InitializePrint, AddressOf grid_InitializePrint End Try End Sub Private Sub grid_InitializePrint(sender AS Object, e as CancelablePrintEventArgs) e.PrintLayout.BorderStyle = UIElementBorderStyle.None End Sub
Hi Nathan,
I tried it out using the code you have here and it's working fine for me.
I had to make a couple of small changes to your code. First, you are re-hooking the InitializePrint event in the Finally block. I think you meant to unhook it there. Also, I changed it to show a PrintPreview, instead of printing, so I can test without wasting paper and ink.
I am attaching my sample here. If you run it and click the button, you can see there is no border around the page. If you comment out the code inside the InitializePrint, and try again, you get a border around the page.
Are you talking about some other border?
Hi Mike,
The problem appears to be the fact I'm using a style sheet in my project. When I add the same style sheet to your sample project, I get the border.
Could you tell me what I have to turn off in the style sheet? And why don't I get the same behaviour when I export it to a PDF using UltraGridDocumentExporter.
I've added the sample project with the style sheet.
That I didn't know! I'll bear it in mind for the future. Thanks again.
Okay... but just be aware, you can already modify the PrintLayout to hide columns, expand rows or make other adjustments to the print layout without affecting the on-screen grid. You don't NEED to create a new grid just for that stuff. The only thing the print layout can't do without affecting the on-screen grid, in this case, is override the Style Library. :)
I've decided to have a completely separate grid for the print. I'm going to create a class to generate the grid and form on the fly, remove the styling, print then dispose of it. I do need to hide and resize some columns for the printed version, as well as force the child bands to expand anyway so it's probably best for me to keep them separate
If the client wants any particular formatting then I'll apply it through code.
The only real potential down-side to that approach is:
A) The printed grid will lose all styling. So none of the colors or other styling applied to the on-screen grid will be included in the print.
B) If the grid on-screen paints for any reason during the print, it will lose it's styling temporarily. I think this is unlikely since the print is a synchronous operation, but I could be wrong and it's certainly something to keep in mind.
Thanks for the quick response. Option 2 is a potential can of worms I think I'll steer well clear of.
I've turned off the app styling before print and turned it back on after and it works. Thank you very much.