cnickl said:
I have a DataGridView with rows of data. When I click once on a row the row
will become selected. When I click once on an already selected cell the
DataGridViewCell goes into edit mode. When I double click anywhere on the row
the program executes a subroutine with the data from that row. It works fine
except when ever I double click an already selected row, the cell goes into
edit mode before executing the subroutine. That’s because the click event is
fired before the DoubleClick event. I guess a solution would be to check for
a DoubleClick event in the Click Event handler and if there is a one, don’t
go into edit mode. Right click to edit would work, however I have a context
menu attached to the DataGridView and I don’t like the un-intuitiveness of
that approach. The question is: is there a way to check for the presents of
the DoubleClick message in the queue?
No, because when the Click event is generated, the DoubleClick event has not
yet occurred.
There are two ways to handle this issue:
Option 1: The preferred way is to ensure that your single/double click
responses are complimentary. Like in Windows Explorer, a single click
selects an item, a double click launches it. That way you can monitor and
handle the Click/DoubleClick events individually without worrying about the
other event.
Option 2: If you definitely do not want your single click response to
execute if the user double-clicks, your only option is to launch a timer
after the first click, wait the double-click time
(SystemInformation.DoubleClickTime), and if a second click does not occur,
your timer will execute the response to the first click. The downside to
this option is that your program will seem to lag single clicks by about a
half-second while it waits to see if the second click will occur.