Articles in this section
Category / Section

How to switch between two CultureInfo and vice-versa, dynamically in a WinForms GridControl with the Formula CellType?

2 mins read

Switch between two cultureinfo

Refer to the following steps to switch between two CultureInfo.

  1. Pass the current culture name in the CultureInfo class. As, the System.Globalization.CultureInfo() represents information about a specific culture including the names of the culture.
  2. Assign the new CultureInfo to the Grid's CultureInfo.

C#

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
   string culName = "";
   switch (this.comboBox1.SelectedIndex)
   {
      case 0:
              culName = "en-GB";
              break;
      //English united states
      case 1:
              culName = "en-US";
              break;
      //German culture
      case 2:
              culName = "de-DE";
              break;
   }
   //clear the grid
   this.gridControl1.RowCount = 0;
   this.gridControl1.RowCount = 10;
   this.gridControl1.ColCount = 5;
   //Passing the new culture name and setting the CultureInfo
   System.Globalization.CultureInfo ci = null;
   if (culName.Length == 0)
   {
      ci = System.Globalization.CultureInfo.CurrentCulture;
   }
   else
   {
      ci = new System.Globalization.CultureInfo(culName);
   }
   //Assigning the new culture to Grid's CultureInfo
   this.gridControl1.TableStyle.CultureInfo = ci;
   Application.CurrentCulture = ci;
   GridFormulaEngine.ParseDecimalSeparator = Application.CurrentCulture.NumberFormat.NumberDecimalSeparator.ToCharArray()[0];
   GridFormulaEngine.ParseArgumentSeparator = Application.CurrentCulture.TextInfo.ListSeparator.ToCharArray()[0];
   this.label1.Text = "Current Culture for the grid: " + ci.Name;
}

VB

Private Sub comboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
   Dim culName As String = ""
   Select Case Me.comboBox1.SelectedIndex
       Case 0
                culName = "en-GB"
       'English united states
       Case 1
                culName = "en-US"
       'German culture
       Case 2
               culName = "de-DE"
       End Select
   'clear the grid
   Me.gridControl1.RowCount = 0
   Me.gridControl1.RowCount = 10
   Me.gridControl1.ColCount = 5
   'Passing the new culture name and setting the CultureInfo
   Dim ci As System.Globalization.CultureInfo = Nothing
   If culName.Length = 0 Then
     ci = System.Globalization.CultureInfo.CurrentCulture
   Else
     ci = New System.Globalization.CultureInfo(culName)
   End If
   'Assigning the new culture to Grid's CultureInfo
   Me.gridControl1.TableStyle.CultureInfo = ci
   Application.CurrentCulture = ci
   GridFormulaEngine.ParseDecimalSeparator = Application.CurrentCulture.NumberFormat.NumberDecimalSeparator.ToCharArray()(0)
   GridFormulaEngine.ParseArgumentSeparator = Application.CurrentCulture.TextInfo.ListSeparator.ToCharArray()(0)
   Me.label1.Text = "Current Culture for the grid: " & ci.Name
End Sub

 

Note:

In German language, the sum of the two variables are separated by the semicolon. Example: Sum(a;b)

 

Samples:

C#: Cultureinfo

VB: Cultureinfo

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied