Accepted answer

explicitly cast to a bool?

bool b = true;
bool? b2 = (bool?)b;

in case it's of interest, you can convert bool? to bool. you can do this by first checking hasvalue which will return false if it's null or true if it is not null.

if it does have a value, you can cast to a bool.

bool? b = null;
if (b.hasvalue == false) // it's null
  //initialize b 
  b = false;
else if((bool)b == true)
  // do whatever

check out for bool? to bool conversion.


try convert.toboolean(your checkbox)

below how i tested on my datagridview to check checkbox column and it works fine.

if ( convert.toboolean( dgv.rows[r].cells["delete"].value))
    //do work;


here is a fix:

if (convert.toboolean(chkbox.checked) == true)

or a simpler version:

if (convert.toboolean(chkbox.checked))

as the default condition anticipates the truth of the statement.




dbcontext.implied = new nullable<bool>(yes);


can directly do something like

bool result = true;
bool? tobinddata = (bool?)result;

Related Query

More Query from same tag