如何使用shift键按下在gridview中选择多个单元格 [英] How to select multiple cells in gridview using shift key press

查看:225
本文介绍了如何使用shift键按下在gridview中选择多个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在gridview中使用shift键选择多个单元格按

i want select multiple cells in gridview using shift key press

推荐答案

由于.net默认操作也会更新datagridview的slectedrows,你需要有一个数组保留旧选项:





DataGridViewRow [] old;





将在CellMouseDown更新(在默认.net操作修改您的选择之前):





之后,您可以在RowHeaderMouseClick中进行更改(因为RowHeaderSelect是默认的datagridview选择模式)或使用CellMouseClick进行FullRowSelect并重新选择那些旧的选定行:







As the .net default action will also update the slectedrows of your datagridview you need to have an array to reserve the old selections:


DataGridViewRow[] old;


which will be updated at CellMouseDown (before the default .net action modify your selections):


after that, you can do your changes in RowHeaderMouseClick (as RowHeaderSelect is the default datagridview selectionmode) or use CellMouseClick for FullRowSelect and reselect those old selected rows:



private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
    foreach (DataGridViewRow gr in old)
    {
        if (gr == dataGridView1.CurrentRow)
        {
            gr.Selected = false;
        }
        else
        {
            gr.Selected = true;
        }
    }
}


这篇关于如何使用shift键按下在gridview中选择多个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆