Hi, I need the printpreview to reproduce the view of the ultragrid exactly as it is, background colours and all. How can I achieve this? I read in a very old post that it wasn't possible but wanted to know if that's still the case. Attached is an image of my grid and the result of PrintPreview. Thank you.
Public Sub Print_grid(ByVal xGrid As Infragistics.Win.UltraWinGrid.UltraGrid) Try If xGrid.Rows.Count = 0 Then Exit Sub Dim doc As New System.Drawing.Printing.PrintDocument Dim Marg As New System.Drawing.Printing.Margins Marg.Left = 0 Marg.Right = 0 Marg.Top = 0 Marg.Bottom = 30 doc.DefaultPageSettings.Margins = Marg doc.DefaultPageSettings.Landscape = True xGrid.PrintPreview(xGrid.DisplayLayout, doc) Catch ex As Exception MsgBox(ex.Message & " // Print_grid // " & xGrid.FindForm.Name & "." & xGrid.Name) End Try End Sub
Hello,
In order to understand the issue , I set up a sample of UltraGrid with ultraPrintPreviewDialog and everything you set on the grid does shows in the ultraPrintPreviewDialog by default.
Here is my sample for the reference. If my sample is not the correct demonstration of the issue then feel free to modify it and send me back or you can share your own sample for further investigation.
WindowsFormsApplication39.zip
Thank you so much Divya Jain!
But how would you do, for instance, if you have a numeric column and, when the cell value is above 50, you need the cell to be printed in yellow ?
Thank you again
So do you have this condition set in the grid and that is not printing in the printpreview?
Can you share your sample or modify my sample i shared earlier for better understanding of the issue.
Hello again
No, I don´t know how.
In your example, in InitializeLayout, when you did:
e.Layout.Override.CellAppearance.BackColor = Color.Red
that line of code colours all the rows. But is there a way to colour only the first row? (Only the row whose index is 0?)
Thank you
To set the background color of the specific row you can pass the row index like this :
this.ultraGrid1.Rows[0].Appearance.BackColor= Color.Green ;
and to set the backcolor of the specific cell of the row set it like this:
this.ultraGrid1.Rows[0].Cells[index].Appearance.BackColor = Color.Red ;
this.ultraGrid1.Rows[0].Cells[“column name”].Appearance.BackColor = Color.Red ;
Let me know if this helped.
Hello
Divya Jain said:
PrintOreview does not replicate the colouring when I add those lines of code. Attached is an image with more info.
Thank you for the update. I am glad that you are able to achieve your requirement.
Hello again, Divya
Using InitializeRow to check for the condition that causes the colour change finally did the trick, thank you!