(资料图片)
1、rivate void Form1_Load(object sender, EventArgs e) { DataBound(); } ///
/// 绑定数据 /// private void DataBound() { SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=123321;database=pubs"); SqlDataAdapter da = new SqlDataAdapter("select * from jobs"); DataSet ds=new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { this.dataGridView1.DataSource = ds.Tables[0].DefaultView; } } ///
/// 删除按钮 /// ///
///
private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells["选择"].EditedFormattedValue.ToString().Equals("True")) { //删除吧 DataBound(); } } } ///
/// 全选+反选 /// ///
///
private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (this.checkBox1.Checked) { for (int i = 0; i < dataGridView1.Rows.Count; i++) { this.dataGridView1.Rows[i].Cells["选择"].Value = true; } } else { for (int i = 0; i < dataGridView1.Rows.Count; i++) { this.dataGridView1.Rows[i].Cells["选择"].Value = false; } } }哈哈!专门为你写的!感动吧!不明白就发消息呗!。
本文就为大家分享到这里,希望小伙伴们会喜欢。