Click here to Skip to main content
15,888,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working for simple program about Time attendance that connect to Virdi FP devices. There is simple problem which is about numbering row in datagrid so I programmed Arabic application. When numbering datagrid it appears to left and I do not want this. I want it in right format so this is the code I used and the problem in Photo appears

<pre lang="c#">var grid = sender as DataGridView;
 var rowIdx = (e.RowIndex + 1).ToString();

 var leftFormat = new StringFormat()
 {
     Alignment = StringAlignment.Center,
     LineAlignment = StringAlignment.Center
 };

 var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);
 e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, leftFormat);


What I have tried:

C#
var grid = sender as DataGridView;
 var rowIdx = (e.RowIndex + 1).ToString();

 var leftFormat = new StringFormat()
 {
     Alignment = StringAlignment.Center,
     LineAlignment = StringAlignment.Center
 };

 var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);
 e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, leftFormat);
Posted
Updated 23-May-21 1:03am

Why to force doors wide open?

Check out DataGridView Properties (System.Windows.Forms)[^] . There's a RightToLeft[^] property:

Quote:
The RightToLeft property is used for international applications where the language is written from right to left, such as Hebrew or Arabic. When this property is set to RightToLeft.Yes, control elements that include text are displayed from right to left.


This: Column Fill Mode in the Windows Forms DataGridView Control | Microsoft Docs[^] might be interesting too
 
Share this answer
 
v2
Change this code:
C#
var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);


To:
C#
var headerBounds = new Rectangle(e.RowBounds.Right-50, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);


I tried setting it to Right but didn't show up. You should try and adjust the number "50" according to your datagridview size
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900