DataGridView checkbox scan?

  • Thread starter Thread starter Kim
  • Start date Start date
K

Kim

foreach (DataGridViewRow row in this.dataGridView.Rows)
{

if (row.Cells[0].Value.ToString() == "true")
{
return true;

}
}
return false;


I try in a if senctens to scan a datagridview cell but how to test the
checkbox cell I have look for som in books an on the inetenet but not found
somehing.

Best regard
Kim
 
       foreach (DataGridViewRow row in this.dataGridView.Rows)
       {

                if (row.Cells[0].Value.ToString() == "true")
                {
                   return true;

                }
       }
return false;

I try in a if senctens to scan a datagridview cell but how to test the
checkbox cell I have look for som in books an on the inetenet but not found
somehing.

Best regard
Kim

Verify that the cell is of type DataGridViewCheckBoxCell first...
You also might want to verify that the
DataGridViewCheckBoxCell.TrueValue is not null since it's an object
and not a boolean data type.

foreach (DataGridViewRow row in dataGridView.Rows)
{
if (!row.IsNewRow)
{
if (row.Cells[0].GetType() ==
typeof(DataGridViewCheckBoxCell))
{
if ((bool)
(((DataGridViewCheckBoxCell)row.Cells[0]).TrueValue))
{
return true;
}
}
}
}



Cheers
Greg
 
Greg said:
foreach (DataGridViewRow row in this.dataGridView.Rows)
{

if (row.Cells[0].Value.ToString() == "true")
{
return true;

}
}
return false;

I try in a if senctens to scan a datagridview cell but how to test the
checkbox cell I have look for som in books an on the inetenet but not found
somehing.

Best regard
Kim

Verify that the cell is of type DataGridViewCheckBoxCell first...
You also might want to verify that the
DataGridViewCheckBoxCell.TrueValue is not null since it's an object
and not a boolean data type.

foreach (DataGridViewRow row in dataGridView.Rows)
{
if (!row.IsNewRow)
{
if (row.Cells[0].GetType() ==
typeof(DataGridViewCheckBoxCell))
{
if ((bool)
(((DataGridViewCheckBoxCell)row.Cells[0]).TrueValue))
{
return true;
}
}
}
}



Cheers
Greg

Tanks but I just cast by (bool)row.Cells[0].Value == true for the cell
 
Back
Top