1. 添加ContextMenuStrip快捷菜单控件
2. 添加ContextMenuStrip事件
3. DataGridView 右键属性关联ContextMenuStrip
bool isChecked = true;
if (this.dataGridView1.Rows != null)
{
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Selected == true) //该行是否选中
{
this.dataGridView1.Rows[i].Cells[0].Value = isChecked; //勾选改行复选框
}
}
this.dataGridView1.RefreshEdit();
}
添加事件
this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);
this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
this.dataGridView1.CellContentDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentDoubleClick);