Completed
Last Updated: 13 Dec 2017 16:27 by ADMIN
ADMIN
Hristo
Created on: 07 Dec 2017 15:00
Category: GridView
Type: Bug Report
1
FIX. RadGridView - the group row is printed with an indent of 1 pixel compared to the data cells
How to reproduce: check also the attached video
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.radGridView1.DataSource = this.GetData();
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

        GroupDescriptor descriptor = new GroupDescriptor();
        descriptor.GroupNames.Add("Name", ListSortDirection.Ascending);
        this.radGridView1.GroupDescriptors.Add(descriptor);
    }

    private DataTable GetData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Age", typeof(int));
        dt.Columns.Add("Date", typeof(DateTime));
        dt.Columns.Add("Bool", typeof(bool));
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 60; j++)
            {
                dt.Rows.Add("Name " + i, i, DateTime.Now.AddDays(i), i % 2 == 0);
            }

        }

        return dt;
    }

    private void radButton1_Click(object sender, EventArgs e)
    {
        GridPrintStyle style = new GridPrintStyle();
        style.FitWidthMode = PrintFitWidthMode.FitPageWidth;
        this.radGridView1.PrintStyle = style;

        RadPrintDocument doc = new RadPrintDocument();
        doc.HeaderHeight = 30;
        doc.HeaderFont = new Font("Arial", 12);
        doc.LeftHeader = "Left Header";
        doc.MiddleHeader = "Middle header";
        doc.RightHeader = "Right header";
        doc.AssociatedObject = this.radGridView1;

        RadPrintPreviewDialog dialog = new RadPrintPreviewDialog(doc);
        dialog.Show();
    }
}

Workaround: create a custom GridPrintStyle class
public class MyGridPrintStyle : GridPrintStyle
{
    protected override BaseGridPrintRenderer InitializePrintRenderer(RadGridView grid)
    {
        BaseGridPrintRenderer rend = base.InitializePrintRenderer(grid);
        if (rend is TableViewDefinitionPrintRenderer)
        {
            return new MyTableViewDefinitionPrintRenderer(grid);
        }

        return rend;
    }
 
}

public class MyTableViewDefinitionPrintRenderer : TableViewDefinitionPrintRenderer
{
   
    public MyTableViewDefinitionPrintRenderer(RadGridView grid)
        : base(grid)
    {
    }     

    protected override void PrintRowWideCell(GridViewRowInfo row, TableViewRowLayout rowLayout, GridPrintSettings settings, int currentX, int currentY, Graphics graphics)
    {
        int groupLevel = row.Group != null ? row.Group.Level + 1 : 0;
        int indentLevel = row.HierarchyLevel + 1 - groupLevel;
        Size cellSize = this.GetRowSize(row, rowLayout);
        int cellX = currentX + indentLevel * settings.HierarchyIndent + rowLayout.Owner.CellSpacing;
        Rectangle cellRect = new Rectangle(cellX, currentY, cellSize.Width - indentLevel * settings.HierarchyIndent, cellSize.Height);
        CellPrintElement printCell = new CellPrintElement();

        if (row is GridViewGroupRowInfo)
        {
            if (this.PrintPages.Count > 0 && !settings.PrintHierarchy)
            {
                cellRect.Width -= this.PrintPages[this.CurrentPrintPage].Count - 1;
            }

            printCell = this.CreateGroupCellPrintElement(row as GridViewGroupRowInfo);

            if (printCell.Font != settings.GroupRowFont)
            {
                if (settings.GroupRowFont != null)
                {
                    printCell.Font = settings.GroupRowFont;
                }
                else
                {
                    settings.GroupRowFont = printCell.Font;
                }
            }
        }

        printCell.TextPadding = this.GridView.PrintStyle.CellPadding;
        printCell.RightToLeft = this.GridView.RightToLeft == RightToLeft.Yes;

        PrintCellFormattingEventArgs formattEventArgs = new PrintCellFormattingEventArgs(row, null, printCell);
        this.OnPrintCellFormatting(formattEventArgs);


        PrintCellPaintEventArgs paintEventArgs = new PrintCellPaintEventArgs(graphics, row, null, cellRect);
        this.OnPrintCellPaint(paintEventArgs);

        formattEventArgs.PrintCell.Paint(graphics, paintEventArgs.CellRect);

    }
}
Attached Files:
0 comments