This project is read-only.

Print cell background colors

Jul 6, 2010 at 10:12 PM

When printing a grid, is it possible to print the cell view as well. 

When i use the below code, the printout shows everything except for the individual cell background colors, which are important in this grid.

Private Sub PrintButtonClick(ByVal sender As Object, ByVal e As EventArgs)

Dim psd As New PageSetupDialog
Dim ppd As New PrintPreviewDialog() 


 With psd
.AllowMargins = True
.AllowOrientation = True
.AllowPaper = True
.AllowPrinter = True
.ShowHelp = True
.ShowNetwork = True

Dim pd As New SourceGrid.Exporter.GridPrintDocument(Me.Calendar)
pd.RangeToPrint = New SourceGrid.Range(0, 0, Me.Calendar.Rows.Count - 1, Me.Calendar.Columns.Count - 1)
pd.PageHeaderText = "Lab Schedule" & vbTab & vbTab & "From: " + dtp_ProjectStart.Value.Month.ToString + "/" + dtp_ProjectStart.Value.Day.ToString + "/" + dtp_ProjectStart.Value.Year.ToString + " - " + dtp_ProjectEnd.Value.Month.ToString + "/" + dtp_ProjectEnd.Value.Day.ToString + "/" + dtp_ProjectEnd.Value.Year.ToString
pd.PageTitleText = vbTab & "Lab Schedule"
pd.PageFooterText = vbTab & "Page [PageNo] from [PageCount]"
ppd.Document = pd
.Document = pd
End With

If psd.ShowDialog() = Windows.Forms.DialogResult.OK Then 
End If 
End Sub

Jul 11, 2010 at 8:36 AM

Printing background cell colour is not implemented

Jul 12, 2010 at 4:35 PM

Thanks for the reply.

Are there any plans in the future to accommodate that?


Jul 12, 2010 at 6:50 PM

Now, I haven't actually ever used the print feature, but I've briefly opened up example #52.

It seems that I was able to accomplish what you're looking for by making a small modification to GridPrintDocument.cs...


First find the Draw Cell method, it looks like this:


protected virtual void DrawCell(Graphics g, CellContext ctx, RectangleF rect)


Then find this if statement:

if ( ctx.Cell.View is SourceGrid.Cells.Views.Cell )

At the end of it add:

m_CellPrintView.BackColor = ((Cells.Views.Cell)ctx.Cell.View).BackColor;

You will then need to recompile SourceGrid, etc etc... but make sure to backup before making the modification because I don't know if adding that line breaks anything!

Jul 13, 2010 at 8:31 AM

Thanks cerilia, that's quite an easy and straightforwad.



no, there are no plans in the future to add this, unless someone volunteers to do that.


Jul 20, 2010 at 5:13 PM


That was exactly what I needed.  I did make a few changes though.  I changed "Backcolor" to "Background" (this allowed me to print graidients).

i also added m_CellPrintView.Forecolor = ((Cells.Views.Cell)ctx.Cell.View).Forecolor;  (This allowed me to print light colored fonts on the cells that have dark backgrounds)


Aug 26, 2010 at 3:42 PM

When I created grid printing I intentionaly did not print bacground colors as this is how it's needed in most cases but for these rare case where other formating options are needed there is virtual DrawCell method.

The best option in your case is not to edit SourceGrid code (this way you could lose your changes when upgrading to newer version). What I would do is to create new class that extends from SourceGrid printing class and override DrawCell method.

Jul 2, 2014 at 7:41 AM