views:

329

answers:

6

how can I add a double click event to a control that doesn't have a double click event =P

like a combo box!!!

+6  A: 

<sarcasm>Use more exclamation points - that usually gets the job done!</sarcasm>

But, seriously, you can't. Try checking for the simple "Click" event and then see if the time between two successive clicks is small enough. I'm not sure where you can find the system double-click timing though. Try googling for that.

However, I would seriously think twice about adding such non-standard behavior to a standard control. Users normally don't expect this so they will quite likely be unhappy about this. Remember - the best UI is the one that offers the user least surprises. Better think of another way to do what you are trying to do.

Vilx-
A: 

According to my copy of Reflector, System.Windows.Forms.ComboBox, from assembly System.Windows.Forms, Version 2.0.0.0, DOES have a DoubleClick event.

David
Yup, and the MSDN agrees. However, the documentation for the event says "This event supports the .NET Framework infrastructure and is not intended to be used directly from your code. This event is not relevant for this class." (see http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.doubleclick.aspx).
Corin
A: 

The TextBox control inside the combobox steals/consumes the DoubleClick event, so you have to use the Click event on the ComboBox to listen for both clicks?

Source

lance
+3  A: 

The short answer is you don't.

The long answer is you subscribe to the Click event and see if another click event was called in the last XXX milliseconds, as in this post.

Matthew Jones
that was fast =] thanks to all
Luiscencio
A: 

I was unable to find a way (given that the text box eats the event); I also saw a note that double click is not relevant for this control. I also did not find a way to capture the event from the inner text control

You may want to rethink why you want to change the behavior from the default (namely, selecting the current text). If you change expected behavior too much, your application becomes that much harder to use.

Kathy Van Stone
+3  A: 

Actually a System.Windows.Forms.ComboBox has a DoubleClick event, it's just hidden from your editor:

 // Summary:
 //     This event is not relevant for this class.
 [EditorBrowsable(EditorBrowsableState.Never)]
 [Browsable(false)]
 public event EventHandler DoubleClick;

I'm guessing they chose to hide the event because it won't ever be called :)

csharptest.net