Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I'm trying to find a simple way to prevent fractional or decimal numbers in my datagridview. All I want to do is show a simple messagebox that tells the user that only whole numbers are allowed. Here is what I have so far.

VB
If (e.ColumnIndex = 1) Then 'This will specify which column 
            Dim cellData = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
            If cellData Is NotWholeNum Then 'I don't know how to prevent non-whole numbers
                MessageBox.Show("Only Whole Numbers Allowed")
                DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = "DefaultValue" 'This will supply a default value back to the datagridviewcell

                Exit Sub

            End If
Posted

1 solution

VB
If CType(cellData, int) <> cellData Then


Assuming cellData is a numeric value, that should work.
 
Share this answer
 
v2
Comments
CAS1224 25-Jun-13 12:16pm    
Thanks so much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900