1

How to test for DataGridViewCell.Value with Option Strict On?

If DataGridViewCell.Value = "some value" then

Gives the error:

Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.

EDIT:

The Solution is:

If DataGridViewCell.Value.ToString = "some value" then
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143

1 Answers1

2

The error message doesn't match your code snippet, that error can't be generated by an assignment. Being forced to guess, use the ToString() method:

 If DataGridViewCell.Value.ToString() = "some value" Then

Or use the CStr() operator, that's more VB-ish.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536