datagridview中checkbox如何使其勾上

2024-07-25 01:09:11
推荐回答(4个)
回答1:

我的全选是这样的,是可以的呀
//循环dataGridView
for (int i = 0; i < dgvOperation.Rows.Count; i++)
{
//设置设置每一行的选择框为选中,第没空余一列为checkbox
dgvOperation.Rows[i].Cells[0].Value = true;
}
这个是反选的作用
//枯滚循环dataGridView
for (int i = 0; i < dgvOperation.Rows.Count; i++)
{
/亏纯/判断当前行是否被选中
if ((bool)dgvOperation.Rows[i].Cells[0].EditedFormattedValue == true)
//设置每一行的选择框为未选中
dgvOperation.Rows[i].Cells[0].Value = false;
else
//设置每一行的选择框为选中
dgvOperation.Rows[i].Cells[0].Value = true;
}

回答2:

因为你没有数据空高源不能绑定。。。。。
string sql=""斗纯尺;
DataSet ds = new DataSet("ds");
ds.Clear();
ds.Tables.Add("vlab_nlzb");
ds.Tables["vlab_nlzb"].Columns.Add(new DataColumn("bh", typeof(Boolean)));
ds.Tables["vlab_nlzb"].Columns["bh"].DefaultValue = false;
SqlDataAdapter sda = new SqlDataAdapter(mysql, 链接conn自己写);
sda.Fill(ds, "vlab_nlzb");
this.dataGridView2.DataSource = ds.Tables["vlab_nlzb"];
if (ds.Tables["vlab_nlzb"].Rows.Count > 0)
{
Boolean.Parse((this.dataGridView2.CurrentRow.Cells["bh"] as DataGridViewCheckBoxCell).Value.ToString());
}

这样就可以绑定数据裤弊源了。别忘了给分啊。。。。

回答3:

  比如说,有没有设置过表格能否编辑(为了不让编辑其他的单梁顷元格),如果不能编辑的话,导致这个checkbox也不能勾选。核渣昌
  也有可能是每个datagridviewrow的改扒属性设置成了readonly,也导致不能勾选。
  DataGridViewCheckBoxColumn column9 = new DataGridViewCheckBoxColumn();
  column9.HeaderText = "是否选择";
  column9.ReadOnly = false;
  m_dgvSalesCommissionsSearch.Columns.Add(column9);

回答4:

checkbox chkbx =dgpermissions.Rows[j].Cells[i].findcontrol("歼橘键氏巧checkboxid"伍悉) as checkbox;
chkbx.checked = true;