I have a datagridview with one DataGridViewCheckBoxColumn and some other TextBox Columns. I want to loop through each cell and see if the checkbox is checked then do something. I am using the following looping method. Is there a better way to do??
I have used or condition because in some computers it brings .Value
as Checked and in some it bring .Value
as true.
foreach (DataGridViewRow row in dataGridView.Rows)
{
if ((bool)(row.Cells["Checkbox"]).Value || (CheckState)row.Cells["Checkbox"].Value == CheckState.Checked)
{
// Do something
}
}
Thanks in advance.
i think this will be faster than foreach
for (int i = 0; i < dataGridView.Rows.Count -1; i++)
{
DataGridViewRow row = dataGridView.Rows[i];
if ((bool)(row.Cells["Checkbox"]).Value
|| (CheckState)row.Cells["Checkbox"].Value == CheckState.Checked)
{
// Do something
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With