Reputation: 305
I need help formatting individual cells in this datagridview. For instance, the last cell needs to be formatted to two decimal places. The remaining cells are fine the way they are except I will also need to set entry limits on all of them. For instance, Oil Flow entry must be between 0 and 300, etc.. I'm pretty certain I can figure that part out though. I'm having difficulties with formatting the individual cells though. I've tried the following line of code in the cellformatting event but it doesn't work for some reason because it does work in a Initialize subroutine that I execute right after the Form Load event.
dgvPresets.Item(1, 10).Style.Format = "0.00"
Thank you
Upvotes: 1
Views: 9930
Reputation: 2180
You can handel DataGridView1_CellFormatting
:
Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
If e.ColumnIndex = 1 AndAlso IsNumeric(e.Value) Then
e.Value = Format(e.Value, "#,##0.00")
End If
End Sub
Upvotes: 1
Reputation: 694
Try this :
dgvPresets.Rows(10).Cells(1).ValueType = GetType(Double)
dgvPresets.Rows(10).Cells(1).Style.Format = "N2"
Upvotes: 4