Decimals and thousands separators in a numeric DataGrid Column


I’d like column1 of my datagrid to be formatted to display numbers with a fixed number of decimals (e.g. 1, 2 or 3) and yet be formatted with  thousands  separators.

Does anyone know how to do that?

To format with thousands separators this is the code I use but it doesn’t allow for decimals:

Dim dgTextBoxColumn1 As DataGridTextBoxColumn = MyDataGrid.TableStyles("tProduits").GridColumnStyles("MyColumn")
dgTextBoxColumn1.Format = "#,#"

Any help shall be greatly appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you need to create TableStyle

Public Sub AddFormattedColumn()
    Dim tsProducts As New DataGridTableStyle
    tsProducts.MappingName = "Products"

    ' Create a new column style
    Dim csUnitPrice As New DataGridTextBoxColumn()
    csUnitPrice.MappingName = "UnitPrice"
    csUnitPrice.HeaderText= "Unit Price"
    ' Set the format of the column
    ' NOTE: The data must be of type Integer to for it to be
    ' formatted correctly as a currency.
    csUnitPrice.Format = "c"

End Sub

Format   Input                                                   Output
d           February 12, 1976                                 2/12/1976
D           February 12, 1976                                 Thursday, February 12, 1976
T           11:38:00 PM                                         11:38:00 PM
t            11:38:00 PM                                         11:38 PM
F           Thursday, February 12, 1976 11:38:16 PM Thursday, February 12, 1976 11:38:16 PM
f            Thursday, February 12, 1976 11:38:16 PM Thursday February 12, 1976 11:38
C           32.98                                                   $32.98


 Dim col1 As DataGridTextBoxColumn
   col1 = New DataGridTextBoxColumn()
   col1.TextBox.Enabled = False
   col1.Format = "[#0]" 'write number in [..]
   col1.Alignment = HorizontalAlignment.Right
   col1.HeaderText = "ID"
   col1.MappingName = "employeeid"
   Dim col2 As DataGridTextBoxColumn
   col2 = New DataGridTextBoxColumn()
   col2.HeaderText = "Last Name"
   col2.MappingName = "lastname"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GhanisenAuthor Commented:
Hi Iboutchkine,

My question wasn't about currency data but only plain numeric data. So it should be "n" instead of "c".

I found also another way to do it with a custom format:

 Dim dgTextBoxColumn6 As DataGridTextBoxColumn = _
               dgr.TableStyles("tProduits"). _
        ' Format avec séparateur de milliers prédéfini
        dgTextBoxColumn6.Format = "#.#0,000"

The number of 0 after the coma determines the number of decimals. It works.

Thank you for your effort. You still deserve 500 points. Bye Iboutchkine.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.