How do I set the RightToLeft
property for a particular DataGridViewCell in a DataGridViewColumn?
I know it's an old question, but as others said, DataGridViewCell
and DataGridViewColumn
don't have the RightToLeft
property. However, there are workarounds to this problem:
Handle the CellPainting
event and use the TextFormatFlags.RightToLeft
flag:
private void RTLColumnsDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == RTLColumnID && 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;
}
}
(Code taken from CodeProject question.)
If it's only one particular cell in the DGV, you may try to insert the invisible RTL character (U+200F) in the beginning of the cell content.
Such a property does not exist. You need to set the RightToLeft
property of the entire control.
I suspect that you're attempting to mis-use the property to right-justify your text. It's intended to enable support for locales that use right-to-left fonts, not for custom formatting.
If altering formatting is your goal, each DataGridViewCell
has a Style
property that accepts an instance of the DataGridViewCellStyle
class. You can set its Alignment
property to "MiddleRight" to align the content of the cell vertically at the middle and horizontally at the right. For more information, see: How to: Format Data in the Windows Forms DataGridView Control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With