Reputation: 1473
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.
Upvotes: 7
Views: 1669
Reputation: 1473
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;
}
}
Upvotes: 6
Reputation: 2924
To work correctly with RightToLeft languages you should set CSS style rtl. For example:
private void CustomizeCellsInThirdColumn()
{
int thirdColumn = 2;
DataGridViewColumn column =
dataGridView.Columns[thirdColumn];
DataGridViewCell cell = new DataGridViewTextBoxCell();
cell.Style.Direction = "rtl";
column.CellTemplate = cell;
}
For more information read CSS direction Property and DataGridViewCell.Style Property
direction: rtl;
Upvotes: 0