Solved show 2 decimal places in a DataGridView

Posted on 2011-11-01
Last Modified: 2012-05-12

I use the following code to populate a DataGridView on a Windows form.
I need to show the results to two decimal places even if the number
is 125.00.
How do I do this?
Sub FillDGV_Supplier()

            Dim sSQL As String

            If Me.ComboBox_SupplierStatus.SelectedIndex = 0 Then
                sSQL = "Select * From [Q3 Supplier Totals]"
            ElseIf Me.ComboBox_SupplierStatus.SelectedIndex = 1 Then
                sSQL = "Select * From [Q3 Supplier Totals Unpaid]"
            ElseIf Me.ComboBox_SupplierStatus.SelectedIndex = 2 Then
                sSQL = "Select * From [Q3 Supplier Totals Paid]"
            End If

            Dim connection As New OleDbConnection(ConnectionString)
            Dim dataadapter As New OleDbDataAdapter(sSQL, connection)
            Dim ds As New DataSet()
            dataadapter.Fill(ds, "Suppliers_table")
            DataGridView_Supplier.DataSource = ds
            DataGridView_Supplier.DataMember = "Suppliers_table"


            'Me.DataGridView_Supplier.Columns(1).Width = 25

        Catch ex As Exception
        End Try

    End Sub

Open in new window

Question by:murbro
    LVL 17

    Accepted Solution

    You can do like this

    Me.DataGridView_Supplier.Columns("UnitPrice").DefaultCellStyle.Format = "c"

    Author Closing Comment

    thanks very much

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now