How to add thousand and decimal separators for decimal values in Devexpress Xtragrid columns

Ingredients:
  • Developer Express 2010 or above
  • An Xtragrid
  • VS 2008
Steps:
In the design view of your form, locate the grid's column that contains the decimal value. Left-click that column to choose it and press F4 to open the properties window. In the properties window of your selected column locate the DisplayFormat property. Click the plus symbol near the DisplayFormat property to open the containing hidden properties.

In the FormatType property you can choose Numeric and enter N in the FormatString. You can also determine how many places will appear after the decimal point by adding the numbers of digits after the ‘N’ character. For example, N2 means your decimal number will contain two decimal places.

Now your grid column has been formatted to display decimal numbers with thousand and decimal separators but your computer culture settings will determine if the thousand separator is the "," (comma) symbol while the decimal separator is the "." (dot) symbol . To check your regional settings you can go to:
  • Control Panel -> Regional and Language Options (Win XP).

  • Control Panel -> Clock, Language, and Region -> Regional and Language Options (Win 7).
However, if you would like to change the symbols of the thousand separator and decimal point without changing your computer's culture then you can use CSharp code to change the Culture of your program. By doing this the format of your decimal values in your program will be determined by the culture of your program not the culture of your computer.

CSharp code:

using System.Globalization;
using System.Threading;
Thread.CurrentThread.CurrentCulture = new CultureInfo("your-culture-info");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("your-culture-info");
VB code
Imports System.Globalization
Imports System.Threading
Thread.CurrentThread.CurrentCulture = New CultureInfo("your-culture-info")
Thread.CurrentThread.CurrentUICulture = New CultureInfo("your-culture-info")
These lines of codes can be put in the form's source code or in the CSharp program.cs file.


No comments:

Post a Comment

Blog Archive

About Me

My photo
I am a software developer with roughly 5 years of experience in developing end-to-end solutions in C#, Java, C/C++, PHP and HTML/CSS/Javascript. At the moment, I am joining the Professional Doctorate in Engineering degree program in Software Technology at Eindhoven University of Technology. My areas of particular interest include software design, data structures and algorithms, problem solving, software security, embedded system, machine learning, and data science.