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

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
 
P

Paul E Collins

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

Zytan

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
 
Z

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
 

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