Solved

Datagrid: Number formatting

Posted on 2004-10-28
1,354 Views
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.

msali.
0
Question by:msali
    3 Comments
     
    LVL 19

    Expert Comment

    by:arif_eqbal
    You need to Format the particular Column of the DataTable
    Use DataGrid Table Style and TextBox Column Style to do it
    eg.

            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

    0
     

    Author Comment

    by:msali
    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")
            dsFiles.Tables.Add(dtFiles)
            grdFiles.ParentRowsVisible = False
            grdFiles.DataSource() = dsFiles
            grdFiles.DataMember = "Files"

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


    Thanks.
    0
     
    LVL 19

    Accepted Solution

    by:
    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
    ts1.GridColumnStyles.Add(Col)

    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Product Review - Android Remix

    Come along for the ride with our Senior Product Manager, Brian Matis, as he reviews the Android Remix.

    Suggested Solutions

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    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…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video discusses moving either the default database or any database to a new volume.

    845 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

    Need Help in Real-Time?

    Connect with top rated Experts

    5 Experts available now in Live!

    Get 1:1 Help Now