Reputation: 3787
I've set the SelectionMode for my DGV to FullRowSelect and MultiSelect to true.
Because this is going to be used on a touch screen where the user may not have access to a keyboard to hold the control or shift buttons down while selecting items, I would like to emulate the behavior that the ListBox uses with its MultiSimple mode.
I'm wondering what the easiest way to do this might be. My first thought was to capture the mouse down event and then 'press' the control key for the user, but I'm actually not sure how I would do that though. I know how to use SendKeys, but I'm thinking that would just press & release the control key rather than giving me the ability to choose when the button is released.
Suggestions?
EDIT: I have tried the solution listed here: Select multiple Rows without pressing Control Key
The problem with this solution is that it looks horrible when the screen flickers every time you change the selection. I would like something that doesn't give potential customers a bad impression of the product.
The way I see it, the only way to do this is either to be able to simulate holding the control button down when the user clicks, or else to prevent the datagrid from deselecting other rows when the user clicks. Suggestions on how to do either of these things would be greatly appreciated.
Upvotes: 0
Views: 252
Reputation: 2746
I would override the original DataGridView
class and change the OnCellMouseDown
event.
Code as follows:
public partial class MyDataGridView : DataGridView
{
public MyDataGridView()
{
}
protected override void OnCellMouseDown(DataGridViewCellMouseEventArgs e)
{
this.Rows[e.RowIndex].Selected = !this.Rows[e.RowIndex].Selected;
}
}
I tried it on my machine with DataGridView
containing more than 1000 rows and it works pretty well (no flickering).
The problem with this approach is the case where your DataGridView
cells are editable. But I don't see a reason to combine MultiSelect
along with editable cells, it just make no sense.
Upvotes: 1