?
Solved

VB.net show 2 decimal places in a DataGridView

Posted on 2011-11-01
2
Medium Priority
?
1,348 Views
Last Modified: 2012-05-12
Hi

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()
        Try

            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()
            connection.Open()
            dataadapter.Fill(ds, "Suppliers_table")
            connection.Close()
            DataGridView_Supplier.DataSource = ds
            DataGridView_Supplier.DataMember = "Suppliers_table"

            Total_Supplier_Boxes()

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

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

Open in new window

0
Comment
Question by:Murray Brown
2 Comments
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 2000 total points
ID: 37061900
You can do like this

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

Author Closing Comment

by:Murray Brown
ID: 37061911
thanks very much
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 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