foreach (DataGridViewRow dgR in this.dataGridView1.Rows)
{
try
{
DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)dgR.Cells[0];
if ((bool)cbx.FormattedValue)
{ //TO DO
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
try
{
DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)dgR.Cells[0];
if ((bool)cbx.FormattedValue)
{ //TO DO
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
提供另一方式:
//計算出勾選筆數
int count = 0;
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
if (this.dataGridView1.Rows[i].Cells[0].FormattedValue.ToString() == "True")
{
count++;
}
}
MessageBox.Show("勾選的筆數有: ["+count.ToString()+"] 筆");
沒有留言:
張貼留言