Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Datagrid: Number formatting

Posted on 2004-10-28
Medium Priority
Last Modified: 2012-06-21
Hi experts,
I have created a dynamic data table and added a following column to it.

        dtFiles.Columns.Add("Size", GetType(Long))

Now when I add the data to it I use the following line of code

newRow("Size") = FileLen(ofdlg.FileNames(i))


Problem: I am unable to fortamt the number, e.g., if the file size is 2322, I want it to appear like, 2,322

How do I achieve it, yet I do not want to change the datatype to string as it is does not perform well in sorting.

Thanks in adv.

Question by:msali
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 19

Expert Comment

ID: 12431327
You need to Format the particular Column of the DataTable
Use DataGrid Table Style and TextBox Column Style to do it

        Dim ts1 As New DataGridTableStyle
        ts1.MappingName = "Table1" 'The Name of table in the DataTable

        Dim Col As New DataGridTextBoxColumn
        Col.MappingName = "Size" 'Name of Column in the Table
        Col.HeaderText = "Size"
        Col.Width = 100
        Col.Format = "N" 'Set the Format to Numeric
        ts1.GridColumnStyles.Add(Col) 'Add the Column Style to TableStyle

       DataGrid.TableStyles.Add(ts1) 'Add the Table Style to DataGrid


Author Comment

ID: 12432857
arif eqbal, i tried what you suggested, but it gives me an error that "Size" is already defined in my DataGridStyles.

So I uesed the RemoveAt method to remove the Size column from my grid style and then added it again but now it as added it at the end of my grid.

FYI: following is the code that I have written for mapping grid with cols and styles

        dsFiles = New DataSet("Files")
        grdFiles.ParentRowsVisible = False
        grdFiles.DataSource() = dsFiles
        grdFiles.DataMember = "Files"

        Dim grdStyle As New DataGridTableStyle
        grdStyle.MappingName = dsFiles.Tables("Files").TableName

LVL 19

Accepted Solution

arif_eqbal earned 500 total points
ID: 12434794
Just before the last line in your posted code add the following lines

  Dim Col As New DataGridTextBoxColumn
        Col.MappingName = "Size" 'Name of Column in the Table
        Col.HeaderText = "Size"
        Col.Width = 100
        Col.Format = "N" 'Set the Format to Numeric


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question