torg Posted March 9, 2003 Posted March 9, 2003 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? Quote
Moderators Robby Posted March 9, 2003 Moderators Posted March 9, 2003 here's a full sample on adding to the Format method of a DatagridTextBoxColumn... 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) Quote Visit...Bassic Software
jvcoach23 Posted June 4, 2003 Posted June 4, 2003 I'm tyring to learn from the example above. I've setup my datagrd and it is getting data. I've 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 Quote JvCoach23 VB.Net newbie MS Sql Vet
torg Posted June 4, 2003 Author Posted June 4, 2003 Does any other formatting take place? I.e is the headertext set to "CPU Time" or the width to 60 ? Quote
Moderators Robby Posted June 4, 2003 Moderators Posted June 4, 2003 What date type is "CPUTime" in the database? Are you sure it's Integer? Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.