效果图:
代码实现:
//实现多选功能
//获取第一次选取行的值
private void dataGridView1_MouseClick_1(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && !(Control.ModifierKeys == Keys.Shift))
{
index = this.dataGridView1.CurrentRow.Index;
}
}
//
private void dataGridView1_KeyUp(object sender, KeyEventArgs e)
{
if (this.dataGridView1.SelectedRows.Count > 0)//&& e.KeyData == Keys.Shift
{
int endrow = this.dataGridView1.CurrentRow.Index;
if (index < endrow)
{
for (int i = index; i <= endrow; i++)
{
if (i <= endrow)
{
if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value) == false)
{
dataGridView1.Rows[i].Cells[0].Value = true;
//btn_chooseall_Click(sender,e);
}
}
}
}
}
```