Datagridview Default value as 0 is being considered as Not Numeric

DannyBoy

New member
Joined
May 7, 2011
Messages
3
Programming Experience
Beginner
Hi everyone this is my first post

ok so i have a Datagridview called dgvPartsOrdered and im trying to validate the columns 3 and 4 (which r actually 2 and 3) to be only numeric. The default values of those cells are 0 which i set through the properties (i even formated it as number through the GUI). However, at run time, for some reason the system thinks that those cells are strings if they remain untouched by the user. here is my code

Dim v AsInteger = 0
DoWhile (v + 1) < dgvPartsOrdered.RowCount
IfNot IsNumeric(dgvPartsOrdered.Rows(v).Cells(2).Value) OrNot IsNumeric(dgvPartsOrdered.Rows(v).Cells(3).Value) Then
MsgBox("The inputs in the quantity fields may only contain numbers", vbExclamation, "Invalid Entry")
dgvPartsOrdered.Focus()
Exit Sub
EndIf
v = v + 1
Loop

I tryed putting the CInt(dgvPartsOrdered.Rows(v).Cells(2).Value) but that won't work because if the user inputs a letter it will crash.
I hope i was explicit enough. So is there anyway around this?

thanks
 
The problem would be that you have set the default value to a String containing a "0" character rather than the number zero.

No, I went in the properties and set it to number and null value 0. It's weird that i was getting that error. but i fixed it with some code
 
DannyBoy said:
the properties
Which ones? The DataGridView columns default cell style properties? :) The talk about default value should indicate DefaultValue of a DataColumn, but in last post you mention 'null value' which is something else.
NullValue is what is displayed when the cell Value is Nothing or DBNull.Value, neither which are numeric. DataGridViewCellStyle.NullValue Property (System.Windows.Forms)
 
Back
Top