I have a DataGridView with a column where the user can insert double. I have to control the cell value before i insert in my database because the table have a number(10,2) datatype for this field.
My current code :
Dim length As Integer = Nothing
Dim row As Integer = DTG.CurrentCell.RowIndex
Dim column As Integer = DTG.CurrentCell.ColumnIndex()
With DTG(row).Cells(column)
length = Len(.Value)
If Not IsNothing(.Value) Then
If Not IsNumeric(.Value) Then
.Value = 0
End If
If length > 10 Then
.Value = .Value.SubString(0, 10)
If .Value.Contains(".") Then
.Value = .Value.SubString(0, 9)
End If
End If
End If
End With
The length method is not appropriate here, because if my cell contains ".", the length increases.
Examples :
1234567891 => length = 10 => insert : 1234567891
123456789.1 => length = 11 => insert : 123456789
In the 2nd case, i need to insert 123456789.1
Can someone advise me ? Thank you