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
stackexchange12
  • 622
  • 9
  • 20
  • 41

1 Answers1

0

I think it no necessary to use select string

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

matzone
  • 5,703
  • 3
  • 17
  • 20
  • I still want it to show "Not Used" if the user types in anything except ".32" – stackexchange12 Jun 26 '13 at 00: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 '13 at 00:49