locked
how to add decimal number in the datagridview RRS feed

  • Question

  • this is my code

     Private Sub diagnosis_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            table.Columns.Add("ID", Type.GetType("System.String"))
            table.Columns.Add("Date", Type.GetType("System.String"))
            table.Columns.Add("Tooth Surf No.", Type.GetType("System.String"))
            table.Columns.Add("Procedure", Type.GetType("System.String"))
            table.Columns.Add("Dentist", Type.GetType("System.String"))
            table.Columns.Add(New DataColumn() With {.ColumnName = "Amt. Charged", .DataType = GetType(Single)})
            table.Columns.Add(New DataColumn() With {.ColumnName = "Paid", .DataType = GetType(Single)})
            table.Columns.Add(New DataColumn() With {.ColumnName = "Bal", .DataType = GetType(Single)})
            table.Columns.Add("Next Appointment", Type.GetType("System.String"))
            DataGridView1.DataSource = table
        End Sub

    And this is my code to add a data in my Datagridview

     Private Sub btnadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
                table.Rows.Add(txtboxid.Text, l1.Text, txtboxno.Text, cbservice.Text, ComboBox1.Text, txtboxprice.Text, txtboxpaid.Text, txtboxbal.Text, txtboxappointment.Text)
         End Sub

    but the datagridview didnt show the decimal point in my column 

    ColumnName = "Amt. Charged"
    ColumnName = "Paid"
    ColumnName = "Bal"


    • Edited by no[one] Saturday, November 24, 2018 2:17 PM
    Saturday, November 24, 2018 2:17 PM

Answers

  • try to use Microsoft.VisualBasic.FormatNumber

    or

    Set Column Format like this DataGridView.Columns("Paid").DefaultCellStyle.Format = "#,##0.00"

    • Edited by Xan To Saturday, November 24, 2018 2:23 PM
    • Proposed as answer by Xan To Saturday, November 24, 2018 2:23 PM
    • Marked as answer by no[one] Saturday, November 24, 2018 2:59 PM
    Saturday, November 24, 2018 2:23 PM