"ListBox DoubleClick" doesn't handle "select, then press Enter"

  • Thread starter Thread starter Zytan
  • Start date Start date
Z

Zytan

I can handle DoubleClick on a ListBox to respond, not when the
selection changes, but when you double click one to invoke an action.
This is the same as using the keys to move the selection, then
pressing Enter. But, of course, DoubleClick doesn't automatically
handle that.

Is there any way to handle ALL standard UI at once, rather than
checking for DoubleClick and for Enter press manually?

Zytan
 
Zytan said:
Is there any way to handle ALL standard UI at once,
rather than checking for DoubleClick and for Enter press
manually?

No, but you can avoid the duplication by calling one event handler
from the other, as in:

private void myList_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Keys.Return)
{
myList_DoubleClick(sender, EventArgs.Empty);
}
}

If you want every ListBox to behave this way, consider inheriting from
ListBox, adding what you want, and using your derived control instead
of the standard one.

Eq.
 
No, but you can avoid the duplication by calling one event handler
from the other, as in:

private void myList_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Keys.Return)
{
myList_DoubleClick(sender, EventArgs.Empty);
}
}

If you want every ListBox to behave this way, consider inheriting from
ListBox, adding what you want, and using your derived control instead
of the standard one.

Thanks, Paul. I think (I said I think) with Win32, you can just
handle a single message, and it's the same message for them both, so
Win32 is actually easier than the .NET wrappers in this case, weird.

Zytan
 
Small type cast fix:
private void myList_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
myList_DoubleClick(sender, EventArgs.Empty);
}

Zytan
 
Back
Top