score:16

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 http://msdn.microsoft.com/en-us/library/bb384091.aspx for bool? to bool conversion.

score:0

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;
}

score:0

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.

dependencies:

using.system;

score:2

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

score:3

can directly do something like

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

Related Query

More Query from same tag