Results 1 to 5 of 5

Thread: formatting numbers in data grid

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    110

    Question formatting numbers in data grid

    My datagrid doesnot show the numbers (price,rate) in the same format as the SQL query returns....

    means fields like Price, Rate as sent by backend are like this...
    1200.00, 150.00

    but they look in the grid like this

    1200, 150.1

    how do we show the same format as sent by the backend.

    though dates and time donot have this problem...

    please help with the numbers
    Anis Bombaywala

  2. #2
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    use a datagrid style to create a custom datacolumn style you can then set the output display to be in any format you wish

    MSDN has a great little article demonstrating exactly how to customise the datagrid.

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Format these in coming numbers before you put them into the Grid! something similar to this :
    VB Code:
    1. MsgBox(Format(32003, "0#-####"))

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    110

    but my grid get populated this way..

    Dim dv As DataView
    dv = x.GetDataView(SQLString)
    DataGrid1.DataSource = dv

    .... where SQLString is a Procedure Call in which everything is already formatted. Means from backend it comes well formatted. but the same format doesnt show in grid.
    Anis Bombaywala

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Create a template column, and use a custom binding expression for the label in the column. Something like this:

    DataBinder.Eval(Container.DataItem, "MyPriceField", {0:c})

    That is how I do it in ASP.Net with the web datagrid. I haven't checked if it works for the Win Forms datagrid.

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