Click here to Skip to main content
15,885,853 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
i want select multiple cells in gridview using shift key press
Posted
Comments
Maciej Los 23-Apr-15 7:14am    
What have you done till now? Where are you stuck?

1 solution

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:



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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900