I am making various changes to my grid when printing (show grid lines solid, etc). When I''m in the print loop, the grid that''s visible on the main form is changing since I''m working on it in the background during print.
I am saving the original settings and setting them back when I''m done printing.
How do I make these changes not show on the visible version of the grid?
I''ve tried BeginUpdate() / EndUpdate() around the call to Print(), but it doesn''t seem to work.
Quick second question:
How do I make the outer border of the grid show up? On my printouts, the left edge of the grid has no gridlines.
The only ways I would know to do the first task takes work. One way is to use a second grid. If this is a GridControl, you can use grid.Model.SaveBinary to serialize out the grid to a memory stream, and then GridModel.LoadBinary to create a new gridmodel which you can use to create a new gridcontrol passing the new model in the GridControl constructor. Then the changes you make to the copy should not appear in the original grid.
By default, the grid only displays the bottom and right cell borders. If you want to display other borders, you set the style.Borders.Left to a new GridBorder with the properties you want to see. You would do this for the cells in the left most column.
DADanSeptember 1, 2004 03:39 PM UTC
I failed to mention that I''m using a virtual grid. So maybe that helps with the first part? I was hoping there was a better way, but I can create another virtual grid, use the same QueryXXX handlers, and do the printing through that 2nd grid?
For the borders question, again in my virtual grid QueryCellInfo handler, I can set the style.Borders.Left, etc. Just tried it, and even a thin border comes out thicker than the grid lines (which include the right and bottom of the grid).
grid.Model.Options.DefaultGridBorderStyle = GridBorderStyle.Solid;
But that only seems to deal with the grid lines within the grid, not the border.
Any other ways to get at the border other than in style.Borders during QueryCellInfo?
AdministratorSeptember 1, 2004 04:49 PM UTC
There is a grid.Properties.PrintFrame that normally causes a frame to be printed around the grid. It is on by default. So if the frame is not being printed, then you might check to see if you have turned this property off, or if you have modified the page settings for your printing so that this frame is being clipped or something of that nature.
If you are setting grid-wide print properties like showing gridlines that are differ from your display properties, then I think you will need a second grid. If the properties you are changing are on a cell by cell basis that you can change in QueryCellInfo, then you could possibly get by without the second grid. The idea would be to check grid.PrintingMode in QueyCellInfo, and conditionally set the properties based on whether you are printing or not. Doing this in QueryCellInfo should be dynamic enough to know when teh drawing is being done for printing or not. Now I have not tried this so I may be overlooking something.
DADanSeptember 1, 2004 05:12 PM UTC
I''ve tried setting grid1.Model.Properties.PrintFrame = true, and verified at a breakpoint in OnPrintPage that it is still true.
(note that it''s Properties on the model object, is that right?)
I see the same behavior in the PrintToFit sample, which is what my printing is modeled after. (I only set the sample to hide row and col 0)
Enclosed is a picture of the top left corner of the print preview for the grid, showing no frame.
Is there a clipping issue with the PrintToFit sample?
AdministratorSeptember 1, 2004 05:31 PM UTC
In the PrintToFit code, you are printing a bitmap of the grid. The PrintFrame property is not being used since you are not relying on the grid''s printing support. In that sample, you could just draw whatever lines you need. Maybe something like this:
g.DrawImage(gridBM, destRect, srcRect, gu);
g.DrawLine(Pens.Black, destRect.X - 1, destRect.Y, destRect.X - 1, destRect.Bottom);
AdministratorSeptember 1, 2004 09:51 PM UTC
OK - didn''t realize the printing support was ignored when the grid is rendered as a bitmap.
I draw my own rectangle around the edge for the border, so it all works.
DADanSeptember 10, 2004 05:13 PM UTC
Ok, so now I''m heading down the path of making a second grid. I have a helper class that defines all the properties and hooks up the events, so in the print routine, I''m just creating a second grid with (mostly) the same properties as the main display grid, then doing a modified "PrintToFit" on it.
I''m getting an exception in the DrawGrid, that basically looks like the grid Model object is null.
GridControl gridPrint = new GridControl();
GridFunctions gridFuncs = new GridFunctions( this.form, gridPrint );
gridFuncs.CreateGrid( gridPrint, true );
Is the method you metion above, SaveBinary/LoadBinary the best way to get the model setup on the print/second grid? Wondering why my grid model is null, when it''s the same creation functinos I use for both, the display grid works, the print grid crashes.
AdministratorSeptember 10, 2004 08:43 PM UTC
Here is a minimal sample showing how you can use LoadBinary/SaveBinary to create a duplicate grid.
DADanSeptember 28, 2004 04:21 PM UTC
Ok - thanks, so now I have the second copy of the grid, but when I go to print(preview) it, it doesn''t have any of the formatting or data that the original does.
This is a virtual grid - I''ve hooked up all the events for the 2nd grid (not sure if those event settings are carried in the SaveBinary/LoadBinary, so I set them manually after the copy), but none of the QueryXXX events get called when printing.
I''ve attached a simple example that shows the problem.
AdministratorSeptember 28, 2004 04:47 PM UTC
If you are using a virtual grid, you prpbably do not have to serialize the grid as using the virtual events will provide the information (for the most part - if you have explicilly set colwidths, then you would either have to serialize the grid or explicilty set them on the copy grid.)
Here is your sample back with that change. The main reason your original code was not working is that the copy grid had not been added to the forms controls collection. The new sample does this and positions it off the screen so your user cannot see it.