msali
asked on
Datagrid: Number formatting
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.
I have created a dynamic data table and added a following column to it.
dtFiles.Columns.Add("Size"
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.
ASKER
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").Ta bleName
grdFiles.TableStyles.Add(g rdStyle)
Thanks.
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
grdFiles.DataSource() = dsFiles
grdFiles.DataMember = "Files"
Dim grdStyle As New DataGridTableStyle
grdStyle.MappingName = dsFiles.Tables("Files").Ta
grdFiles.TableStyles.Add(g
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(C
DataGrid.TableStyles.Add(t