Format Database Numeric Field to Appear as Currency in DataGrid
Posted on 2006-04-28
I have a datagrid. I would like to have all of my numeric(123123 or 123123.00) fields in my dataset appear as currency($123,123.00 or at least 123,123.00) in my datagrid. It should be fairly dynamic. The grid has over 170 columns and a majority of them are currency. I would prefer not to have to label these columns individually. I have created a loop as below, but I fear I may be using the gridtextboxcolumn incorrectly.
dv = New DataView(MainDataSet.Tables("Company"))
dgCompany.DataSource = dv
dgCompany.AlternatingBackColor = System.Drawing.Color.LightCyan
dgCompany.CaptionVisible = False
Dim ColumnCursor As Integer
Dim TableStyle As New DataGridTableStyle
For ColumnCursor = 0 To (MainDataSet.Tables("Company").Columns.Count - 1)
If MainDataSet.Tables("Company").Columns(ColumnCursor).DataType.ToString = "System.Decimal" Then
dgTextBoxCol = New DataGridTextBoxColumn
dgTextBoxCol.Format = "c"