How to change the format "N2" from DataTable and Show in DataGridView in vb.net

68 Views Asked by At

How to change the DataTable format to "N2" and Show in DataGridView in vb.net?. I want to change the format of the DataTable without going through the DataGridView format and displaying in the DataGridView. Please recommend the best solution. I tried but the result is still in the datagridview has not changed.

Thanks

Private Sub ImprovedCode()
    Dim dt As New DataTable("tbl")
    Dim dtColumn As New DataColumn With {.DataType = GetType(DateOnly), .ColumnName = "CreatedDate"}
    dt.Columns.Add(dtColumn)
    Dim dtColumn2 As New DataColumn With {.DataType = GetType(Double), .ColumnName = "Price"}
    dt.Columns.Add(dtColumn2)
    Dim dr As DataRow = dt.NewRow()
    dr(dtColumn) = DateOnly.FromDateTime(Date.Now)
    dr(dtColumn2) = 120000
    Dim dr1 As DataRow = dt.NewRow()
    dr1(dtColumn) = DateOnly.FromDateTime(Date.Now)
    dr1(dtColumn2) = 130000
    dt.Rows.Add(dr)
    dt.Rows.Add(dr1)
    DataGridView1.DataSource = dt
End Sub

RESULT DATAGRIDVIEW

RESULT DATAGRIDVIEW

DESIRED RESULT DATAGRIDVIEW

DESIRED RESULT DATAGRIDVIEW

0

There are 0 best solutions below