DataGridView Keep Multiple Rows Selected on Left Click
On my DataGridView, I have the SelectionMode set to FullRowSelect. When I s开发者_Python百科elect multiple rows in my DataGridView and left click on a cell, all other rows are deselected and just the row that I left clicked in is select. This does not happen on right click.
How can I set my DataGridView so I can select multiple rows, left click on a cell, and all the same rows stay select?
That could be tough, because it contravenes Windows' standard UI behavior. You may need to have your UI keep track of which rows are selected in the DGV and "restore" the previous selection after a left-click alters it. That leaves you with further problems, though. Namely:
- How/when do you reset the selection?
- If a left-click is not allowed to change the selection, how do you select rows in the first place?
- Et cetera.
The more-comprehensive alternative would be to trap all MouseDown
/Click
events on the DGV and implement your own selection behavior, though I'm not sure to what extent that's even possible with WinForms.
My humble opinion would be to rethink this UI design. Is it going to match users' expectations? :)
Update: An alternative-alternative that's just occurred to me: If this behavior is, for some reason, utterly necessary, your best bet would be to create a custom control that adds a sort of "Selection Locked" state to the DataGridView. The user could then explicitly request this override to Windows' default behavior (by selecting rows and then clicking a Lock button, for example). Constructing such a thing would not be trivial, however.
精彩评论