message queue

G

Guest

Hi

Here is my problem:

I have a control that does one thing when it is clicked and something else
when it is double clicked. However the click event is always fired before the
double click event. Is there any way I can look at the message queue for this
control and determine if the next message is a double click and therefore
disregard the click event?
 
L

Larry Lard

cnickl said:
Hi

Here is my problem:

I have a control that does one thing when it is clicked and something else
when it is double clicked.

Change this. This is utterly confusing and non-intuitive.

Unless you mean something like, for example, a listbox dialog that
selects on click and OKs the dialog on double click. This is natural and
expected.
 
G

Guest

Larry Lard said:
Change this. This is utterly confusing and non-intuitive.

Unless you mean something like, for example, a listbox dialog that
selects on click and OKs the dialog on double click. This is natural and
expected.

Ok, in more detail:

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?
 
G

Guest

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.
 
G

Guest

Thanks, this was very helpfull. i guess i have to rethink the way i handle
the events.
 
C

Cyril Gupta

Hello Jared,

Hmm... I think what you are trying to do is not process the click event if
you see a double click event... Is that right?

Well, I don't really see any easy way to do that, but here's a roundabout,
sorta, potty, really inelegant hack

Use a timer in the click event... and disable it in the doubleclick event

In your timer write your trigger code.

That shoulda work for you.

It's just 'magination

Regards
Cyril Gupta

You can do anything with a little bit of 'magination.
http://www.cyrilgupta.com/blog
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top