show Decimal places in Datagrid

torg

Well-known member
Joined
Nov 7, 2002
Messages
60
Location
Norway
I have an Access table tblMytable and a row myCurrency. Format of myCurrency is set to currency and decimal places are set to 2. When I have filled a dataset whis this table, and try to show values in a datagrid I do not see decimals in the datagrid unless I have written e.g 12,78. If I write 12,00 The value shown in the datagrid is 12 I want it to show 12.00. Anybody got an Idea how to solve this problem?
 
heres a full sample on adding to the Format method of a DatagridTextBoxColumn...
Code:
        Dim dgStyle As New DataGridTableStyle()
        With dgStyle
            .AlternatingBackColor = Color.LightGray
            .BackColor = Color.WhiteSmoke
            .ForeColor = Color.MidnightBlue
            .GridLineColor = Color.Honeydew
            .GridLineStyle = System.Windows.Forms.DataGridLineStyle.Solid
            .HeaderBackColor = Color.MidnightBlue
            .HeaderFont = New Font("Arial", 8.0!, FontStyle.Bold)
            .HeaderForeColor = Color.White
            .LinkColor = Color.Teal
            .MappingName = "Appointments"
            .SelectionBackColor = Color.Yellow
            .SelectionForeColor = Color.DarkMagenta
        End With


        Dim grd5 As New DataGridTextBoxColumn()
        With grd5
            .HeaderText = "Description"
            .MappingName = "Description"
            .Width = 75
        End With

        Dim grd6 As New DataGridTextBoxColumn()
        With grd6
            .HeaderText = "Dur"
            .MappingName = "Duration"
            .Alignment = HorizontalAlignment.Center
            .Width = 30
            .Format = "c"  <<< This will set the column to currency
        End With

        dgStyle.GridColumnStyles.AddRange(New DataGridColumnStyle() {grd5, grd6})
        DataGrid1.TableStyles.Add(dgStyle)
 
Im tyring to learn from the example above. Ive setup my datagrd and it is getting data. Ive setup three columns and syntax that you give and I get the three columns back with the style specified with the exception of the .Format="c". The column stay displaying data as an integer rather than a currency. Do I have to have the column doing a double and then to currency.

The output in the column is something like this

9
0
1200
10

what is the correct format command to get it to be
$9.00
$0.00
$1200.00
$10.00

Here is what my syntax is
Dim objCPUTime As New DataGridTextBoxColumn
With objCPUTime
.MappingName = "CPUTime"
.HeaderText = "CPU Time"
set the width of the column
.Width = 60
set the alignment within the column
.Alignment = HorizontalAlignment.Left
.Format = "c" << set the column to currency
End With

thanks
Shannon
 
Does any other formatting take place? I.e is the headertext set to "CPU Time" or the width to 60 ?
 
Back
Top