Link to home
Start Free TrialLog in
Avatar of hedbusta
hedbusta

asked on

Format Database Numeric Field to Appear as Currency in DataGrid

Hi Experts,
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"
                    TableStyle.GridColumnStyles.Add(dgTextBoxCol)
                End If
            Next

             dgCompany.TableStyles.Add(TableStyle)

TIA,
Neil
ASKER CERTIFIED SOLUTION
Avatar of wtconway
wtconway

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hedbusta
hedbusta

ASKER

Thanks!, That it!

Cheers,
Neil