Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# DataGridView
Hi all,
How can I change the RightToLeft property for the column of a DataGridView and not the whole DataGridView.
 
i.e
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;
       }
   }
 

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

Solution 2

  Permalink  
v2
Rate this: bad
good
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.
  Permalink  
Comments
ManfredRBihy at 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
0 Sergey Alexandrovich Kryukov 404
1 Nirav Prabtani 389
2 Abhinav S 210
3 PIEBALDconsult 160
4 Dave Kreskowiak 155
0 OriginalGriff 7,580
1 Sergey Alexandrovich Kryukov 6,806
2 Maciej Los 3,919
3 Peter Leow 3,693
4 CHill60 2,742


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 5 Dec 2010
Copyright © CodeProject, 1999-2014
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