Hi,
I have a RadGridView control which bind by ColumnGroupsViewDefinition with GridViewColumnGroup.
The grid direction is from right to left.
When I use the PrintPreview methods, the grid in the preview become from left to right.
How can I fix it?
Thank you.
5 Answers, 1 is accepted
Can you please confirm whether use the PrintPreview approach demonstrated on this example? If so, does the FlowDirection flips for the whole control, or for the ColumnGroups only?
Regards,
Ivan Ivanov
Telerik by Progress
Hi,
Thank for your reply.
I don't use silverlight...I use Telerik for winforms.
The method I use is:
RadPrintDocument printDoc =
new
RadPrintDocument();
printDoc.Landscape = isLandscape;
printDoc.RightHeader = header;
printDoc.HeaderHeight = 100;
printDoc.AssociatedObject =
this
;
RadPrintPreviewDialog dialog =
new
RadPrintPreviewDialog(printDoc);
dialog.Size =
new
System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width - 200, Screen.PrimaryScreen.Bounds.Height - 200);
dialog.SetZoom(0.80);
dialog.ShowDialog();
Thank,
Elad
Thank you for writing.
I have logged it in our feedback portal and I have added a vote for it on your behalf. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.
I have also updated your Telerik points.
Currently, the possible solution that I can suggest is to use the following code snippet:
public
class
CustomGridPrintStyle : GridPrintStyle
{
protected
override
BaseGridPrintRenderer InitializePrintRenderer(RadGridView grid)
{
if
(
this
.PrintRenderer !=
null
)
{
this
.PrintRenderer.PrintCellPaint -= renderer_PrintCellPaint;
this
.PrintRenderer.PrintCellFormatting -= renderer_PrintCellFormatting;
this
.PrintRenderer.ChildViewPrinting -= renderer_ChildViewPrinting;
}
BaseGridPrintRenderer renderer =
null
;
if
(grid.ViewDefinition.GetType() ==
typeof
(ColumnGroupsViewDefinition))
{
if
(!(renderer
is
ColumnGroupsViewDefinitionPrintRenderer))
{
renderer =
new
CustomColumnGroupsViewDefinitionPrintRenderer(grid);
}
}
else
if
(grid.ViewDefinition.GetType() ==
typeof
(HtmlViewDefinition))
{
if
(!(renderer
is
HtmlViewDefinitionPrintRenderer))
{
renderer =
new
HtmlViewDefinitionPrintRenderer(grid);
}
}
else
{
if
(!(renderer
is
TableViewDefinitionPrintRenderer))
{
renderer =
new
TableViewDefinitionPrintRenderer(grid);
}
}
renderer.ChildViewPrinting += renderer_ChildViewPrinting;
renderer.PrintCellFormatting += renderer_PrintCellFormatting;
renderer.PrintCellPaint += renderer_PrintCellPaint;
return
renderer;
}
private
void
renderer_PrintCellPaint(
object
sender, PrintCellPaintEventArgs e)
{
this
.OnPrintCellPaint(sender, e);
}
private
void
renderer_PrintCellFormatting(
object
sender, PrintCellFormattingEventArgs e)
{
this
.OnPrintCellFormatting(sender, e);
}
private
void
renderer_ChildViewPrinting(
object
sender, ChildViewPrintingEventArgs e)
{
this
.OnChildViewPrinting(sender, e);
}
}
public
class
CustomColumnGroupsViewDefinitionPrintRenderer : ColumnGroupsViewDefinitionPrintRenderer
{
public
CustomColumnGroupsViewDefinitionPrintRenderer(RadGridView grid) :
base
(grid)
{
}
protected
override
void
PrintRow(GridViewRowInfo row, ColumnGroupRowLayout rowLayout, GridPrintSettings settings,
int
currentX,
int
currentY, Graphics graphics)
{
float
scrollableColumnsOffset = 0f;
float
rightPinnedColumnsOffset = 0f;
foreach
(GridViewColumn col
in
rowLayout.RenderColumns)
{
if
(col
is
GridViewRowHeaderColumn || col
is
GridViewIndentColumn)
{
continue
;
}
float
height = rowLayout.GetRowHeight(row);
RectangleF cellBounds = rowLayout.GetCorrectedColumnBounds(row, col,
this
.GridView.RightToLeft == RightToLeft.Yes,
new
RectangleF(0f, 0f, rowLayout.DesiredSize.Width, height));
if
(cellBounds == RectangleF.Empty)
{
continue
;
}
if
(col.PinPosition == PinnedColumnPosition.Left)
{
if
(scrollableColumnsOffset < cellBounds.Right + rowLayout.Owner.CellSpacing)
{
scrollableColumnsOffset = cellBounds.Right + rowLayout.Owner.CellSpacing;
rightPinnedColumnsOffset = scrollableColumnsOffset;
}
}
else
if
(col.PinPosition == PinnedColumnPosition.None)
{
if
(rightPinnedColumnsOffset < scrollableColumnsOffset + cellBounds.Right + rowLayout.Owner.CellSpacing)
{
rightPinnedColumnsOffset = scrollableColumnsOffset + cellBounds.Right + rowLayout.Owner.CellSpacing;
}
cellBounds.X += scrollableColumnsOffset;
}
else
{
cellBounds.X += rightPinnedColumnsOffset;
}
cellBounds.Offset(currentX, currentY);
GridViewCellInfo cell;
CellPrintElement printCell;
if
(row
is
GridViewTableHeaderRowInfo)
{
cell =
this
.GridView.MasterView.TableHeaderRow.Cells[col.Name];
printCell =
this
.CreateHeaderCellPrintElement(col);
if
(printCell.Font != settings.HeaderCellFont)
{
if
(settings.HeaderCellFont !=
null
)
{
printCell.Font = settings.HeaderCellFont;
}
else
{
settings.HeaderCellFont = printCell.Font;
}
}
}
else
if
(row
is
GridViewSummaryRowInfo)
{
GridViewSummaryRowInfo rowInfo = row
as
GridViewSummaryRowInfo;
cell = rowInfo.Cells[col.Name];
if
(cell ==
null
)
{
continue
;
}
printCell =
this
.CreateSummaryCellPrintElement(cell);
if
(printCell.Font != settings.SummaryCellFont)
{
if
(settings.SummaryCellFont !=
null
)
{
printCell.Font = settings.SummaryCellFont;
}
else
{
settings.SummaryCellFont = printCell.Font;
}
}
}
else
{
cell = row.Cells[col.Name];
if
(cell ==
null
)
{
continue
;
}
if
(col
is
GridViewImageColumn)
{
printCell =
this
.CreateImageCellPrintElement(cell);
}
else
{
printCell =
this
.CreateDataCellPrintElement(cell);
if
(printCell.Font != settings.CellFont)
{
if
(settings.CellFont !=
null
)
{
printCell.Font = settings.CellFont;
}
else
{
settings.CellFont = printCell.Font;
}
}
}
}
printCell.TextPadding =
this
.GridView.PrintStyle.CellPadding;
printCell.RightToLeft =
this
.GridView.RightToLeft == RightToLeft.Yes;
Rectangle rect =
new
Rectangle((
int
)cellBounds.X, (
int
)cellBounds.Y, (
int
)cellBounds.Width, (
int
)cellBounds.Height);
PrintCellFormattingEventArgs formattEventArgs =
new
PrintCellFormattingEventArgs(row, col, printCell);
this
.OnPrintCellFormatting(formattEventArgs);
formattEventArgs.PrintCell.Paint(graphics, rect);
PrintCellPaintEventArgs paintEventArgs =
new
PrintCellPaintEventArgs(graphics, row, col, rect);
this
.OnPrintCellPaint(paintEventArgs);
}
}
}
private
void
radButton1_Click(
object
sender, EventArgs e)
{
CustomGridPrintStyle style =
new
CustomGridPrintStyle();
this
.radGridView1.PrintStyle = style;
RadPrintDocument printDoc =
new
RadPrintDocument();
printDoc.Landscape =
true
;
printDoc.RightHeader =
"Right Header"
;
printDoc.HeaderHeight = 100;
printDoc.AssociatedObject =
this
.radGridView1;
RadPrintPreviewDialog dialog =
new
RadPrintPreviewDialog(printDoc);
dialog.Size =
new
System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width - 200, Screen.PrimaryScreen.Bounds.Height - 200);
dialog.SetZoom(0.80);
dialog.ShowDialog();
}
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik by Progress
Thank you for your reply.
I try to use this code but I have no ChildViewPrinting event and no GetCorrectedColumnBounds method in my Telerik.WinControls.UI reference.
I use Telerik.WinControls.UI version 2013.1.220.40. r=RunTimeVersion v4.0.30319.
How can I use it?
Thank you for writing back.
The provided workaround is applicable for the latest official version R3 2016 SP. I would recommend you to upgrade in order to benefit from all the introduced improvements in the 4 years versions gap.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik by Progress