Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TreeView: How to capture Enter?

3 views
Skip to first unread message

(Pete Cresswell)

unread,
Jan 8, 2005, 3:10:17 PM1/8/05
to
I've got KeyDown coding and it fires when other keys are pressed, but when Enter
is pressed, nothing.

I'd like to support the (standard?) Windows behavior of executing DblClick
processing when an item is selected and the user presses Enter

I got focus to stop moving to the next control via Tools|Options|Keyboard|Move
after enter....but now it just sits there and neither KeyDown nor KeyPress seems
to catch it.

Is this the end of the road?
--
PeteCresswell

David Schofield

unread,
Jan 9, 2005, 4:22:04 PM1/9/05
to

Hi
The KeyDown and KeyUp events don't occur when you press the ENTER key
if the form has a command button for which the Default property is set
to Yes.

So maybe if you make sure it hasn't they will. You will have to to
trap and act on the enter key for command buttons yourself.
HTH
David

(Pete Cresswell)

unread,
Jan 9, 2005, 5:21:21 PM1/9/05
to
Per David Schofield:

>Hi
>The KeyDown and KeyUp events don't occur when you press the ENTER key
>if the form has a command button for which the Default property is set
>to Yes.
>
>So maybe if you make sure it hasn't they will. You will have to to
>trap and act on the enter key for command buttons yourself.
>HTH

No Command buttons w/.Default=True - and I tested that by putting a regular
ListBox on the same form. The regular ListBox's KeyDown event fires when
Return/Enter are pressed (KeyCode=13).

It's starting to sound like the TreeView's behaviour is somewhat different.
--
PeteCresswell

David Schofield

unread,
Jan 10, 2005, 7:15:15 PM1/10/05
to

Hi
Um ...
You can set the form.KeyPreview = true and catch ENTER with KeyDown at
the form level, check that the treeview is active and in a suitable
state (use the treeview events to set up this) and then call your
doubleclick event. But the ENTER will still be passed to the treeview
control as KeyDown doesn't have a cancel argument.

Straightforward subclassing the treeview doesn't catch Enter, but if
you are up for heavy coding see
How To Prevent the ENTER Key From Firing in TreeView Control
http://support.microsoft.com/default.aspx?scid=kb;en-us;216664

This is written for VB.

It is a bold developer who deploys any Access app with treeview in it,
let alone one with subclassing!

David


HTH
David

(Pete Cresswell)

unread,
Jan 10, 2005, 7:44:22 PM1/10/05
to
Per David Schofield:

>It is a bold developer who deploys any Access app with treeview in it,
>let alone one with subclassing!

I've got a couple out there with no reported problems.

("Reported" being the operative word....)


Anything special I should be on the lookout for?
--
PeteCresswell

(Pete Cresswell)

unread,
Jan 10, 2005, 7:53:06 PM1/10/05
to
Per David Schofield:

>ou can set the form.KeyPreview = true and catch ENTER with KeyDown at
>the form level, check that the treeview is active and in a suitable
>state (use the treeview events to set up this) and then call your
>doubleclick event. But the ENTER will still be passed to the treeview
>control as KeyDown doesn't have a cancel argument.

Still no-go.

I checked it with ?frmWhatever.Keypreview in the immediate window....and,
indeed, it still fires KeyDown and KeyPress for the space bar and other
keys...but not Enter.

I think I see why, though. The list is already using Enter to toggle nodes'
.Expanded. Hit Enter on a collapsed node and it expands...do the same thing
on an expanded node and it collapses.

I guess that about wraps it.... I guess I'll just trap SpaceBar and tell the
users to learn to love it.
--
PeteCresswell

David Schofield

unread,
Jan 11, 2005, 5:25:08 AM1/11/05
to

Hi
Problems with common controls arise mainly in MDE/run time systems
when older or newer versions of the DLL are on the user's PC
David

0 new messages