Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RightToLeft DatagridviewCell

How can i sert the property RightToLeft to a DatagridviewCell? I tried to set

Alignement property to "MiddleRight" but since my DatagridviewCell value is

Arabic and English it is not displayed as i want from right to left.

like image 359
user4340666 Avatar asked Mar 10 '15 09:03

user4340666


1 Answers

I found a solution with Cell_Painting event and it works. This is the code:

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    {
        if (e.ColumnIndex == 2 && e.RowIndex >= 0)
        {
            e.PaintBackground(e.CellBounds, true);
            TextRenderer.DrawText(e.Graphics, e.FormattedValue.ToString(), e.CellStyle.Font, e.CellBounds, e.CellStyle.ForeColor, TextFormatFlags.RightToLeft | TextFormatFlags.Right);
            e.Handled = true;
        }
    }
like image 61
user4340666 Avatar answered Nov 07 '22 22:11

user4340666