DataGridView DoubleClick Event handler fails when CTRL key is held while DoubleClicking
-
Hello, I have a DataGridView that is dynamically populated and configured for row select, multiselect = no. When a row is double clicked, an event handler is fired which runs a function based on the Row index. The row index is referenced as follows: myDgv.SelectedRows[0].Cells[2].Value.ToString() This works great, until the user is holding the CTRL key while double clicking. I get an "index out of range error", making me think holding the CTRL key changes the value the above code returns. Has anyone ran into this before? I'm not sure what to do, other than catch the error and fail the event. Any ideas are appreciated! Thanks, Alan
-
Hello, I have a DataGridView that is dynamically populated and configured for row select, multiselect = no. When a row is double clicked, an event handler is fired which runs a function based on the Row index. The row index is referenced as follows: myDgv.SelectedRows[0].Cells[2].Value.ToString() This works great, until the user is holding the CTRL key while double clicking. I get an "index out of range error", making me think holding the CTRL key changes the value the above code returns. Has anyone ran into this before? I'm not sure what to do, other than catch the error and fail the event. Any ideas are appreciated! Thanks, Alan
I think it may have something to do with the index being cell based rather than row based if I hold CTRL. CTRL modifies selection in Windows (as in selecting multiple files at once, or multiple listbox lines at once).
-
I think it may have something to do with the index being cell based rather than row based if I hold CTRL. CTRL modifies selection in Windows (as in selecting multiple files at once, or multiple listbox lines at once).
Ok, figured it out. When I doubleclick on a row while holding CTRL, the dialog selects the row on the first click, but deselects it on the second. The DoubleClick eventhandler fires, references the selected row, and fails as none are selected.