0

I have a DataGridView in Windows Form Application

When I set DataGridView1.RightToLeft = RightToLeft.No the numbers in this DataGridView are displayed in English like this '12345', but When I set it to RightToLeft.Yes the same numbers are displayed in Arabic like this '١٢٣٤٥' and I don't want this, I want numbers always in English

I think this is because my windows language is Arabic so I tried to change Current Culture, but this didn't help and the numbers are still in Arabic

    Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US")
    My.Application.ChangeUICulture("en-US")
    CultureInfo.CurrentUICulture = New CultureInfo("en-US", True)
    CultureInfo.CurrentCulture = New CultureInfo("en-US", True)

So my question is how to make the DataGridView to display numbers always in English regardless of its RightToLeft state and windows language.

Note: I need the DataGridView to be right to left because my application is in Arabic, and I don't want to change windows settings.

For test:

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim dt As New DataTable
    With dt
        .Columns.Add("cc1", GetType(System.Int64))
        .Columns.Add("cc2", GetType(System.DateTime))
        .Columns.Add("cc3", GetType(System.Int64))
        .Columns.Add("cc4", GetType(System.Int64))
        .Rows.Add(555555, Now, 589, 369)
        .Rows.Add(-6666666, Now, 789, 654)
    End With
    Me.DataGridView1.DataSource = dt
    Me.Label1.Text = "4444"
    Me.TextBox1.Text = "7777"
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click        '

    If Me.DataGridView1.RightToLeft = RightToLeft.No Then
        Me.DataGridView1.RightToLeft = RightToLeft.Yes
        Me.Label1.RightToLeft = RightToLeft.Yes
        Me.TextBox1.RightToLeft = RightToLeft.Yes
    Else
        Me.DataGridView1.RightToLeft = RightToLeft.No
        Me.Label1.RightToLeft = RightToLeft.No
        Me.TextBox1.RightToLeft = RightToLeft.No
    End If
End Sub
Fadi
  • 3,302
  • 3
  • 18
  • 41
  • I cannot reproduce the problem, but does setting `dt.Locale = CultureInfo.GetCultureInfo("en-US")` help? Otherwise, is there something about the rendering of the DGV which is using something to convert 0-9 into Arabic characters? – Andrew Morton Dec 16 '19 at 16:39
  • Set that in the `MyApplication_Startup` event: `My.Application.ChangeCulture("en-US")` and `My.Application.ChangeUICulture("en-US")`. and btw, `12345` are _Arabic_ digits while `١٢٣٤٥` are _Indians_. –  Dec 16 '19 at 16:44
  • @AndrewMorton, I now tried `dt.Locale` but it not help. and I don't think the DGV has anything to convert 0-9 to Arabic, I just create new DGV and didn't change anything in it. – Fadi Dec 16 '19 at 16:47
  • 1
    @Fadi You could handle the [DataGridView.CellFormatting Event](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview.cellformatting?view=netframework-4.8) and format the number to a string using the culture you want. – Andrew Morton Dec 16 '19 at 16:53
  • @JQSOFT, I now tried your suggesting, but it not help. – Fadi Dec 16 '19 at 17:00
  • 2
    Then try the Andrew's last comment. And maybe [this](https://stackoverflow.com/questions/6239729/how-can-i-display-culture-specific-native-digits-instead-of-arabic-numerals) and [this](https://stackoverflow.com/questions/51802254/how-to-force-my-c-sharp-windows-forms-to-use-arabic-number?noredirect=1&lq=1) and [this](https://answers.microsoft.com/en-us/windows/forum/windows_7-desktop/can-only-input-arabic-numerals-want-to-input-hindi/9ed4acdd-d128-47ce-8921-a0943dfcbe30) could help. –  Dec 16 '19 at 17:11
  • @AndrewMorton, I will try CellFormatting, Thanks. – Fadi Dec 16 '19 at 17:11
  • Thanks @JQSOFT, I will try Andrew's last comment and look at your suggested links. – Fadi Dec 16 '19 at 17:18
  • 1
    Most welcome abo elfod :) –  Dec 16 '19 at 18:56

0 Answers0