哈哈,谨以此文记住自己的一点笨方法
背景:winform,c#,Datagridview,checkbox 实现自由多选 保证DataGridview的MultiSelect属性值为true
代码中加入如下内容:
全局变量:
private int startrow = -1;
以下是Datagridview的两个事件:
private void dataGridView1_KeyUp(object sender, KeyEventArgs e)
{
if (this.dataGridView1.SelectedCells.Count > 0 && e.KeyData == Keys.ShiftKey)
{
int endrow = this.dataGridView1.CurrentRow.Index;
if (startrow <= endrow)
{
//正序选时
for (int x = startrow; x <= endrow; x++)
{
this.dataGridView1.Rows[x].Cells["我的checkbox列"].Value = 1;