Completed
Last Updated: 15 Aug 2017 10:20 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 05 Jan 2017 07:13
Category: GridView
Type: Feature Request
0
FIX. RadGridView - RightToLeft grid with ColumnGroupsViewDefinition is printed LeftToRight
To reproduce: run the attached sample project. You will notice the result illustrated in the provided screenshot. Although the grid is RTL, the print preview dialog show it in LTR.

Workaround:

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();
}
0 comments