日期:2014-05-18  浏览次数:21049 次

datagridview中的checkbox 的bool值
请问 如何从datagridview中的checkbox 提取bool值
已用 DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn();
  newColumn.HeaderText = "this.studentDataSet2._Sheet1_";
  dataGridView1.Columns.Add(newColumn);

------解决方案--------------------
if (dataGridView1.CurrentRow.Cells[1].Value.ToString() == "True")
------解决方案--------------------
private void button1_Click(object sender, EventArgs e)
{
if (dataGridView1.Rows.Count > 0)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value))
{
MessageBox.Show("选择了第" + (i + 1).ToString() + "行");
}
}
}
}

Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value)这样就转换了

------解决方案--------------------
遍历循环datagridview 的checkbox的那一列,然后如果值为true的话则选中不就行了!
for(int shu=0;shu<datagridview.rows.count;shu++)
{
if(Convert.ToBoolean(dgvyu.Rows[shu].Cells[0].Value) == true
{
//则选中
}
}
------解决方案--------------------
Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value)