We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Alignment of a virtual grid in a printed page

Hi,

We are printing a virtual grid, by adding it to a visible form at location -1000, -1000, wrapping a GridPrintDocument around it, and then calling Print() on the GridPrintDocument. We are setting the margins on the printDocument.PrinterSettings.DefaultPageSettings to zero on all sides, but although the printed grid appears at the top of the page, it is not flush with the left. If there is only one column, then the left-hand side of that column is in the centre of the page. If there are more columns, enough so that if the left-hand side of the first column were in the centre of the page, the right-hand side of the last column would be off the right of the page, then left-hand side is far enough to the right of the centre of the page to make sure that the right-hand side of the last column is on the page.

Or to put it another way - it looks like the code that is positioning the grid on the printed page is (a) trying to centre it, (b) erroneously thinking that the grid is of zero width, and (c) is shifting the grid to the left if the right-hand margin would be off the side of the page.

I hope that's at least reasonably clear...

What I would like to be able to do is to tell the grid to work out its size before it is printed so that (b) does not happen, and to be able to tell the grid to print itself at the top left of the page, so that (a) does not happen.

Or, if my diagnosis is completely wrong and something else is causing the problems I'm seeing - could you perhaps just tell me how to make sure that a virtual grid, when printed, can come out at the top left of the page?


Regards,

Giles

9 Replies

HA haneefm Syncfusion Team April 9, 2007 10:36 AM UTC

Hi Giles,

To customize the printing in a grid, you would handle a couple events on the GridPrintDocument object that you create to do your printing. In its BeginPrint event, you would set the grid margins (in the GridPrintDocument.DefaultPageSettings property) to reserve left and right space, and you may also have to set the GridBounds property. Then in the PrintPage event, you would print your left and right space.

Best regards,
Haneef


CM Christian Muirhead April 12, 2007 02:20 PM UTC

Thanks Haneef -

We're already setting the properties that cover the things you're suggesting:

grid.Properties.PrintColHeader = False
grid.Properties.PrintRowHeader = False
grid.Properties.PrintFrame = False

settings.DefaultPageSettings.Margins.Top = 0
settings.DefaultPageSettings.Margins.Left = 0
settings.DefaultPageSettings.Margins.Bottom = 0
settings.DefaultPageSettings.Margins.Right = 0

Although we aren't setting them in the BeginPrint and PrintPage events. Would this make a difference?

We're using a virtual grid, and are handling the QueryRowCount and QueryColCount events (which should make up the bounds). Do we also need to set the GridBounds property?

Thanks,
Christian


GT Giles Thomas April 13, 2007 10:55 AM UTC

Haneef,

In addition - how do we set the position of the grid on the printed page? Right now, it looks like it's being placed at the top centre.


Regards,

Giles


GT Giles Thomas April 17, 2007 03:22 PM UTC

Hi,

Does anyone at Syncfusion have any thoughts on this? It's becoming a serious issue for us.


Regards,

Giles


AN Anonymous May 8, 2007 10:25 AM UTC

Please respond with a suggestion, or let us know if we haven't provided enough information -- this issue has been blocking us for several weeks now.


HA haneefm Syncfusion Team May 9, 2007 09:43 PM UTC

Hi William,

My sincere appologies in the delay.

This can be acheived by deriving the GridPrintDocument and overriding OnPrintPage Method. Here you can customize it according to your needs.

Please refer to attached sample for implementation.
PrintGridsOnDifferentLocation.zip

Thank you for your patience.

Best regards,
Haneef


GT Giles Thomas June 22, 2007 03:33 PM UTC

Haneef,

Thank you - we had found a workaround shortly after William's post, hence our silence since then. Your suggestion does position the grid correctly on the printed page, but now the row headers are being printed, even though we have set grid.Properties.PrintRowHeader to false. The column headers are not printed.


Regards,

Giles


GT Giles Thomas June 26, 2007 11:32 AM UTC

So is there any way to not only position the grid on the printed page but also suppress the printing of row and column headers?


Regards,

Giles


HA haneefm Syncfusion Team June 26, 2007 02:36 PM UTC

Hi Giles,

If you want to suppress the printing of row header and column header in a grid, then handle the QueryColWidth/QueryRowHeights event(s).

In your event handler, if e.Index point to a rowheader/col header that you don't want to print and if grid.PrintingMode is true, then set e.Size = 0. This will essentially hide any column header/row header you don't want to see. Below is a code snippet

this.grid.Model.QueryRowHeight += new GridRowColSizeEventHandler(Model_QueryRowHeight);
this.grid.Model.QueryColWidth += new GridRowColSizeEventHandler(Model_QueryColWidth);

void Model_QueryColWidth(object sender, GridRowColSizeEventArgs e)
{
if (this.grid.PrintingMode
&& e.Index == 0)
{
e.Size = 0;
e.Handled = true;
}
}

void Model_QueryRowHeight(object sender, GridRowColSizeEventArgs e)
{
if (this.grid.PrintingMode
&& e.Index == 0)
{
e.Size = 0;
e.Handled = true;
}
}

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon