如何使用Option Strict On设置DataGridViewCell.Value

时间:2011-10-21 14:44:21

标签: c# .net vb.net datagridview option-strict

如何使用Option Strict On测试DataGridViewCell.Value?

If DataGridViewCell.Value = "some value" then

给出错误:

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

修改

解决方案是:

If DataGridViewCell.Value.ToString = "some value" then

1 个答案:

答案 0 :(得分:2)

错误消息与您的代码段不匹配,分配无法生成该错误。被迫猜测,使用ToString()方法:

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

或者使用CStr()运算符,这更像是VB-ish。