1、 checkbox点击事件
private void myStyleDataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)View Code
{
if ((e.ColumnIndex >= 0) && ((this.myStyleDataGridView1.Columns[e.ColumnIndex].Name.ToString().ToUpper() == "IsSelect".ToUpper()) && (e.RowIndex >= 0)) )
{
if (this.myStyleDataGridView1[e.ColumnIndex, e.RowIndex].Value == null)
{
this.myStyleDataGridView1.Rows[e.RowIndex].Cells["IsSelect"].Value = false;
}
if (this.myStyleDataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString().ToUpper() == "TRUE".ToUpper())
{
this.myStyleDataGridView1[e.ColumnIndex, e.RowIndex].Value = false;
}
else
{
this.myStyleDataGridView1[e.ColumnIndex, e.RowIndex].Value = true;
}
}
getTotal();
}
2、统计选中的行数
/// <summary>View Code
/// 统计
/// </summary>
private void getTotal()
{
int j = 0;
strCol003 = "";
for (int i = 0;i<this.myStyleDataGridView1.RowCount;i++)
{
if ((myStyleDataGridView1.Rows[i].Cells["IsSelect"].Value+"").ToUpper() == "TRUE")
{
j++;
strCol003 += "'" + myStyleDataGridView1.Rows[i].Cells["col_003"].Value+"" + "',";
}
}
strCol003 = strCol003.TrimEnd(',');
}
3、全选
private void ckAll_Click(object sender, EventArgs e)View Code
{
for (int count = 0; count < this.myStyleDataGridView1.Rows.Count; count++)
{
DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.myStyleDataGridView1.Rows[count].Cells["IsSelect"];
if (ckAll.Checked)
{
this.myStyleDataGridView1.Rows[count].Cells["IsSelect"].Value = true;
this.myStyleDataGridView1.SelectAll();
}
else
{
this.myStyleDataGridView1.Rows[count].Cells["IsSelect"].Value = false;
}
}
getTotal();
}