469,612 Members | 2,468 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,612 developers. It's quick & easy.

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

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

Apr 4 '07 #1
3 5508
"Zytan" <zy**********@gmail.comwrote:
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.
Apr 4 '07 #2
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

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

Apr 5 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by VK | last post: by
19 posts views Thread by VB Programmer | last post: by
1 post views Thread by Dib | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.