Try something like this.
Public Class Form1
Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
If Not DataGridView1.Rows(e.RowIndex).IsNewRow Then
If DataGridView1.Columns(e.ColumnIndex).Name.Equals("RatingColumn") Then
If Not e.Value.ToString.Contains(",") AndAlso Not e.Value.ToString.Contains(".") Then
e.Value = e.Value.ToString & ",00"
End If
If e.Value.ToString.Contains(".") Then
e.Value = e.Value.ToString.Replace(".", ",")
End If
End If
End If
End Sub
Sub DataGridView1_CellValidating(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
Dim cell As DataGridViewCell = DataGridView1.Item(e.ColumnIndex, e.RowIndex)
If cell.IsInEditMode Then
Dim c As Control = DataGridView1.EditingControl
If DataGridView1.Columns(e.ColumnIndex).Name = "RatingColumn" Then
Dim DecValue As Decimal = 0
If Not Decimal.TryParse(c.Text, DecValue) Then
MessageBox.Show("Not valid")
e.Cancel = True
End If
End If
End If
End Sub
End Class
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via
my MSDN profile but will not answer coding question on either.
VB Forums - moderator
