Completed
Last Updated: 10 Feb 2016 12:27 by ADMIN
ADMIN
Hristo
Created on: 01 Dec 2015 14:18
Category: GridView
Type: Bug Report
0
FIX. RadGridView - the printed header cells have an incorrect text alignment when the grid is in right-to-left mode
How to reproduce:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.radGridView1.DataSource = this.GetData();
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        this.radGridView1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;

        foreach (var col in this.radGridView1.Columns)
        {
            col.HeaderTextAlignment = ContentAlignment.MiddleLeft;
        }
    }

    private DataTable GetData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Date", typeof(DateTime));
        dt.Columns.Add("Bool", typeof(bool));
        dt.Columns.Add("Bool1", typeof(bool));
        dt.Columns.Add("Bool2", typeof(bool));
        for (int i = 0; i < 50; i++)
        {
            dt.Rows.Add("Name " + i, DateTime.Now.AddMinutes(i), i % 2 == 0 ? true : false, false, false);
        }

        return dt;
    }

    private void radButton1_Click(object sender, EventArgs e)
    {
        this.radGridView1.PrintPreview();
    }
}



Workaround: 

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.radGridView1.DataSource = this.GetData();
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        this.radGridView1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
        this.radGridView1.PrintCellFormatting += radGridView1_PrintCellFormatting;

        foreach (var col in this.radGridView1.Columns)
        {
            col.HeaderTextAlignment = ContentAlignment.MiddleLeft;
        }
    }

    private void radGridView1_PrintCellFormatting(object sender, PrintCellFormattingEventArgs e)
    {
        if (e.Row is GridViewTableHeaderRowInfo && this.radGridView1.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
        {
            e.PrintCell.TextAlignment = ContentAlignment.MiddleRight;
        }
    }

    private DataTable GetData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Date", typeof(DateTime));
        dt.Columns.Add("Bool", typeof(bool));
        dt.Columns.Add("Bool1", typeof(bool));
        dt.Columns.Add("Bool2", typeof(bool));
        for (int i = 0; i < 50; i++)
        {
            dt.Rows.Add("Name " + i, DateTime.Now.AddMinutes(i), i % 2 == 0 ? true : false, false, false);
        }

        return dt;
    }

    private void radButton1_Click(object sender, EventArgs e)
    {
        this.radGridView1.PrintPreview();
    }
}
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments