Click here to Skip to main content
12,949,481 members (60,652 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all,
How can I change the RightToLeft property for the column of a DataGridView and not the whole DataGridView.

I want my DataGridView to contain two columns, one RightToLef and the other one LeftToRight.

Solution found:
Handle the DataGridView.CellPainting event and add the following code, which simply draws the cell and align it to the right and rtl flags.

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;


Posted 5-Dec-10 0:16am
Updated 5-Dec-10 2:44am
ManfredRBihy 5-Dec-10 8:47am
Hi Gabi, I moved your solution to your question. Thanks for sharing!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can't - you can only change the RightToLeft property for a control: DataGridViewColumn is not a control, so it does not have a RightToLeft property.
ManfredRBihy 5-Dec-10 7:25am
My vote of 5: Answer is technically correct as you can't control it directly using DataGridViewTextColumn.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,489
CHill60 3,330
Maciej Los 2,913
Jochen Arndt 1,935
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web01 | 2.8.170524.1 | Last Updated 5 Dec 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100