DataGridView checkbox scan?

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
 
G

Greg

       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
 
K

Kim

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top