Script error CS0252

How can I fix this?

Cast to the primitive bool instead of Boolean also add parentheses around that statement to the left of the equality so that it casts first before comparing

I do not get it, could you explain this. It use ToString or just (String)

if((Boolean)_row.Cells[“Calculated_Selected”].Value==true)

You need parentheses around the casted term (left side) so that it casts first and then compares

Right now it’s trying to cast the result of comparing an object to the bool true

Also I would cast to the primitive bool instead of the object Boolean

if( (bool)(_row.Cells[“Calculated_Selected”].Value) )

No real reason to have the “== true” part since the value of the field should be true or false anyways.

2 Likes

I tried this one but it does not work.

if((bool)(_row.Cells[“Calculated_Selected”].Value).ToString()==true)

OR
if((bool)(_row.Cells[“Calculated_Selected”].Value).ToString()==(“true”))

Don’t get hung up on the error message ..., cast the left hand side to type 'string' from the original post.

What @hmwillett posted will work:

NOTE: If you copy/paste his example you will probably need to fix the quotation marks around Calculated_Selected.

It does not work. I did try typing everything, or just modified it.

Thank you

@Gino Is there something different with the Unallocated Grid Calculated_Selected column? You have the same condition on a different grid at 492 and it does not get a warning? Have you tried to run it with the warning to see if it will work anyway?

For giggles and grins, how about trying:

if(Convert.ToBoolean(_row.Cells["Calculated_Selected"].Value))

Joe

Thank you Joe

But its not working.

Gino

Have you run this in the debugger? It may shed some additional details on the value you are getting from the Calculated_Selected column.