Results 1 to 10 of 10

Thread: datagrid format

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    datagrid format

    I'm need to add a $ to one of my fields in the datagrid...heres the code I'm using to format the cell and get the data....anyone tell me how to add a $ to this field?


    VB Code:
    1. Dim grdColStyle4 As New DataGridTextBoxColumn()
    2.         With grdColStyle4
    3.             .HeaderText = "Receipt Amt"
    4.             .MappingName = "transaction_amt"
    5.             .Width = 100
    6.             .Alignment = HorizontalAlignment.Center
    7.             .ReadOnly = True
    8.         End With
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    If the field is numeric this should do.
    VB Code:
    1. Dim grdColStyle4 As New DataGridTextBoxColumn()
    2.         With grdColStyle4
    3.             .HeaderText = "Receipt Amt"
    4.             .MappingName = "transaction_amt"
    5.              [b].Format="#$"[/b]
    6.             .Width = 100
    7.             .Alignment = HorizontalAlignment.Center
    8.             .ReadOnly = True
    9.         End With
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    thank you.


    the way you had it puts the $ sign behind the amount
    .Format="$#"
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by EyeTalion
    thank you.


    the way you had it puts the $ sign behind the amount
    .Format="$#"
    ?? My code puts after, (.Format="#$")
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  5. #5

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    the amount came out like this is the datagrid....


    10.21$

    I changed the format property and it came out right.
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  6. #6

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    is there a way to use .Format = "$#", if the field can be null....I don't want a $ sign in the cell if theres no data?
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  7. #7
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by EyeTalion
    is there a way to use .Format = "$#", if the field can be null....I don't want a $ sign in the cell if theres no data?
    I am not aware of any way. Why dont you format the field while selecting from the database? There you can put the $ if its not null.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  8. #8
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    use null.text = "" and the field will be blank, or null.text = "$0.00" and that will appear

  9. #9

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    doesn't seem to be working...is this right?


    VB Code:
    1. With grdColStyle5
    2.             .HeaderText = "Sales Tax"
    3.             .MappingName = "sales_tax_amt"
    4.             .NullText = ""
    5.             .Format = "$#"
    6.             .Width = 75
    7.             .Alignment = HorizontalAlignment.Center
    8.             .ReadOnly = True
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  10. #10
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    Here is a full working example, showing what I mean, different coding style to yours but the same elements
    Dim t1 As New DataGridTableStyle
    t1.MappingName = "BankRecs"
    ' Add Date
    Dim r3 As New DataGridTextBoxColumn
    r3.MappingName = "Date"
    r3.HeaderText = "Date"
    r3.TextBox.TextAlign = HorizontalAlignment.Center
    r3.Format() = "dd/MM/yyyy"
    r3.Width = 80
    r3.NullText = ""
    t1.GridColumnStyles.Add(r3)

    ' Add Reference
    Dim r4 As New DataGridTextBoxColumn
    r4.MappingName = "Reference"
    r4.HeaderText = " Reference"
    r4.Width = 90
    r4.NullText = ""
    t1.GridColumnStyles.Add(r4)
    ' Add Debit Amount
    Dim r5 As New DataGridTextBoxColumn
    r5.MappingName = "DebitAmount"
    r5.HeaderText = " Debit"
    r5.TextBox.TextAlign = HorizontalAlignment.Right
    r5.Format() = "##,##0.00"
    r5.Width = 90
    r5.NullText = ""
    t1.GridColumnStyles.Add(r5)
    ' Add Credit Amount
    Dim r6 As New DataGridTextBoxColumn
    r6.MappingName = "CreditAmount"
    r6.HeaderText = " Credit"
    r6.TextBox.TextAlign = HorizontalAlignment.Right
    r6.Format() = "##,##0.00"
    r6.Width = 90
    r6.NullText = ""
    t1.GridColumnStyles.Add(r6)

    ' Add account
    Dim r1 As New DataGridTextBoxColumn
    r1.MappingName = "Account"
    r1.Width = 0
    r1.NullText = ""
    t1.GridColumnStyles.Add(r1)
    ' Add Timestamp
    Dim r2 As New DataGridTextBoxColumn
    r2.MappingName = "TimeStamp"
    r2.Width = 0
    r2.NullText = ""
    t1.GridColumnStyles.Add(r2)
    ' Add TranType
    Dim r7 As New DataGridTextBoxColumn
    r7.MappingName = "TranType"
    r7.Width = 0
    r7.NullText = ""
    t1.GridColumnStyles.Add(r7)
    DataGrid1.TableStyles.Add(t1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width