1、属性设置checkboxcolumn
name:cb_check falsevalue:false truevalue:true
datagridview中的readonly设置为false.
2、 //单项选择设置
private void dgv_zy_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int count = Convert.ToInt16(dgv_zy.Rows.Count.ToString());
for (int i = 0; i < count; i++)
{
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dgv_zy.Rows[i].Cells["cb_check"];
Boolean flag = Convert.ToBoolean(checkCell.Value);
if (flag == true) //查找被选择的数据行
{
checkCell.Value = false;
}
continue;
}
}
3、获取选择的数据
int count = Convert.ToInt32(dgv_zy.Rows.Count.ToString());
for (int i = 0; i < count; i++)
{
//如果DataGridView是可编辑的,将数据提交,否则处于编辑状态的行无法取到
dgv_zy.EndEdit();
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dgv_zy.Rows[i].Cells["cb_check"];
Boolean flag = Convert.ToBoolean(checkCell.Value);
if (flag == true) //查找被选择的数据行
{
//从 DATAGRIDVIEW 中获取数据项
string z_zcode = dgv_zy.Rows[i].Cells[0].Value.ToString().Trim();
//........................................ }
}