110,499
社区成员
发帖
与我相关
我的任务
分享
//以下是界面上复选框的事件代码
private void ckbAll_CheckedChanged(object sender, EventArgs e)
{
foreach (DataGridViewRow dr in this.dataGridView1.Rows)
{
if (dr.Cells["PAll"].Value.ToString() != ckbAll.Checked.ToString())
{
dr.Cells["PAll"].Value = ckbAll.Checked;
}
}
}
//以下是当第一列checkbox选中状态改变时,触发2,3,4,5列选中状态改变
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
//PAll列由选择状态变成未选状态
if (this.dataGridView1.Columns[e.ColumnIndex].Name == "PAll")
{
if (this.dataGridView1.Rows[e.RowIndex].Cells["PAll"].Value.ToString() == "False")
{
this.dataGridView1.Rows[e.RowIndex].Cells["PInsert"].Value = "False";
this.dataGridView1.Rows[e.RowIndex].Cells["PDelete"].Value = "False";
this.dataGridView1.Rows[e.RowIndex].Cells["PUpdate"].Value = "False";
this.dataGridView1.Rows[e.RowIndex].Cells["PSelect"].Value = "False";
}
else
{
this.dataGridView1.Rows[e.RowIndex].Cells["PInsert"].Value = "True";
this.dataGridView1.Rows[e.RowIndex].Cells["PDelete"].Value = "True";
this.dataGridView1.Rows[e.RowIndex].Cells["PUpdate"].Value = "True";
this.dataGridView1.Rows[e.RowIndex].Cells["PSelect"].Value = "True";
}
}
}
}
//批量更新到数据库的代码
public bool ExecuteBatchCommandBySQL()
{
OpenCon();//打开数据库连接
SqlDataAdapter sd = new SqlDataAdapter();
sd.SelectCommand = new SqlCommand("select * from PurSpecAnnPopedom", con);
SqlCommandBuilder scb = new SqlCommandBuilder(sd);
try
{
lock (this)
{
sd.Update(ds.Tables["Popedom"]);
}
}
catch (Exception ex)
{
throw ex;
}
return true;
}
foreach (DataGridViewRow dr in this.dataGridView1.Rows)
{
if (dr.Cells["PAll"].Value.ToString() != ckbAll.Checked.ToString())
{
dr.Cells["PAll"].Value = ckbAll.Checked;
}
}
改成
for(int i = 0;i<this.dataGridView1.Rows.length,i++)
{
if(this.dataGridView1.Rows[i].Cells["PAll"].Value.ToString()!=ckbAll.Checked.ToString())
{
this.dataGridView1.Rows[i].Cells["PAll"].Value = ckbAll.Checked
}