By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,894 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,894 IT Pros & Developers. It's quick & easy.

DataGridView checkbox scan?

P: n/a
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
Jul 2 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Jul 2, 4:16*am, Kim <K...@discussions.microsoft.comwrote:
* * * *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
Jul 2 '08 #2

P: n/a


"Greg" wrote:
On Jul 2, 4:16 am, Kim <K...@discussions.microsoft.comwrote:
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
Jul 3 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.