简体   繁体   中英

C# datagridview row select with CTRL and SHIFT

I need to implement datagridview selection in that way so when user clicks a cell whole row is selected, when user holds CTRL key additional rows are selected, when user holds SHIFT key range of rows are selected. According to requirement I cannot show RowHeaders so selection should be based on cell clicking. I also know that datagridview.SelectionMode = FullRowSelect will do the trick but I'm getting one problem when using SHIFT for selection - gaps. When someone selects one row, then presses SHIFT and then jumps over few row to select anoter not all cells became selected(look at the picture - rows with x=3,4,5 have cells which are not selected).

在此处输入图像描述

Help me to solve this problem.

Actually I have some ideas. For example, somehow treat clicking on a cell as clicking on a rowheader, but I'm not sure how to implement this.

datagridview.SelectionMode = FullRowSelect

and

datagridview.RowHeaderVisible=false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM