0

I'm trying to find a way to only allow a user to input ".32" or "Not Used" into my datagridviewcell. Right now my code stands as below. When I run the code all it does is change everything to "Not Used". Even if I type in ".32" it will change it to "Not Used". Is there anyway to fix this? I appreciate any help or suggestions anyone can give.

If (e.ColumnIndex = 6) Then ' This specifies the column number
        Dim cellData = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString
        If cellData Is Nothing OrElse IsDBNull(cellData) OrElse cellData.ToString = String.Empty Then
            MessageBox.Show("Cannot Be Empty") ' This will prevent blank datagridviewcells
            DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = "Not Used"
        End If

        Select Case cellData
            Case 0.32
                DataGridViewSize.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = 0.32
            Case Else
                DataGridViewSize.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = "Not Used"
        End Select
    End If
2
  • The code checks for 0.32, why do you expect it to do anything when you enter 4?
    – Guffa
    Jun 25, 2013 at 23:44
  • thanks for the catch! Typo Jun 26, 2013 at 0:17

1 Answer 1

0

I think it no necessary to use select string

Better you change to Dim cellData = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value

2
  • I still want it to show "Not Used" if the user types in anything except ".32" Jun 26, 2013 at 0:45
  • if your DGV is databound then you can't put string to numeric field .. put any number such as 0 or -1 then use cellformatting wether field with value 0 or -1 will display "Not Used" ..
    – matzone
    Jun 26, 2013 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.