473,394 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

TreeView: How to capture Enter?

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
Nov 13 '05 #1
7 8381
On Sat, 08 Jan 2005 20:10:17 GMT, "(Pete Cresswell)" <x@y.z> wrote:
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


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

Nov 13 '05 #2
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
Nov 13 '05 #3
On Sun, 09 Jan 2005 22:21:21 GMT, "(Pete Cresswell)" <x@y.z> wrote:
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

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...b;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

Nov 13 '05 #4
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
Nov 13 '05 #5
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
Nov 13 '05 #6
On Tue, 11 Jan 2005 00:44:22 GMT, "(Pete Cresswell)" <x@y.z> wrote:
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

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

Nov 13 '05 #7
TheSmileyCoder
2,322 Expert Mod 2GB
I was just myself searching for a solution to the above problem without any luck, but as I did find (partly based on the above) a solution I will post it here, even if it is a quite old thread.


First you must ensure that the Form previews the key pressed before the control. Enter your form properties and find the property called "Key Preview" and set it to TRUE.

This part is optional, but I decided to add a public enum to make it easier for myself to see the keycodes, so this goes into a public module:
Expand|Select|Wrap|Line Numbers
  1. Public Enum Keys
  2.    Enter = 13
  3.    Spacebar = 32
  4.    NoKey = 0
  5. End Enum
Now write code for the Key_Down event of the form, and notice I use it for both my treeview and my listview:
Expand|Select|Wrap|Line Numbers
  1.    'Only react to keyStroke=enter(13)
  2.    If KeyCode <> Keys.Enter AND Keycode<>Keys.Spacebar then Exit Sub
  3.  
  4.    'Respond accordingly to which control is the active control
  5.       Select Case Me.ActiveControl.Name
  6.          Case Me.TreeProjects.Name
  7.             'Treeview is active, determine active node (if any)
  8.                Dim tv As TreeView
  9.                Set tv = Me.TreeProjects.Object
  10.                If Not tv.SelectedItem Is Nothing Then
  11.                   Custom_TreeProjects_NodeSelect tv.SelectedItem
  12.                End If
  13.  
  14.             'Cancel enter keystroke
  15.                KeyCode = Keys.NoKey
  16.  
  17.          Case Me.listReports.Name
  18.             Select Case KeyCode
  19.                Case Keys.Enter
  20.  
  21.                Case Keys.Spacebar
  22.                   Dim lv As MSComctlLib.ListView
  23.                   Set lv = Me.listReports.Object
  24.                   If Not lv.SelectedItem Is Nothing Then
  25.                      OpenReport getID(lv.SelectedItem)
  26.                   End If
  27.             End Select
  28.             'Cancel enter keystroke
  29.                KeyCode = Keys.NoKey
  30.  
  31.       End Select
  32.  
  33. exitSub:
  34.    Set tv = Nothing
  35.    Set lv = Nothing
  36.  
  37.  
  38. End Sub
The Original poster doesn't say so, but I think when he tried this, he kept using the Treeviews KeyDown event, after turning on Key Preview, and thus failed to move the tracking into the forms Key_down (Which occurs any control reacts to Key_Down, thus why it is called Preview)
Aug 22 '12 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Hrvoje Voda | last post by:
What is wrong in this code? private void tree_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter ) {
1
by: Matthew Wieder | last post by:
Hi - I wanted to capture the enter button on a form since I have a datagrid with the first column being a delete button and if someone hits enter it deletes the first record. I coded: private...
2
by: clsmith66 | last post by:
In a treeview, I am trying to store the index of every treenode as it expands in a hidden input box. If I click on the node itself, it expands and I can capture the node index no problem. If I...
5
by: ewillyb | last post by:
Hi, ASP.NET has some interesting behavior when the user hits the Enter key. If there are multiple ASP:Buttons (rendered as HTML submits) on the form, when the user hits enter, the first button's...
2
by: Bernie Yaeger | last post by:
I have an mdi app that has a main menu on the parent form. I would like to use a treeview in place of one of the menu options, so that instead of a menu option - say, 'reports' - it would have...
0
by: ali element via .NET 247 | last post by:
(Type your message here) -------------------------------- From: ali element Hi, I have a IE treeview which I can populate on the fly. However,when I hit the page the following property must...
2
by: rolf.oltmans | last post by:
Hello all, I need to place treeview control in Grid control. I need to place it in a grid because I need to show calendar against every node. Is placing a treeview in grid possible? If I need...
0
by: hardieca | last post by:
Hi, I have created a treeview bound to a sitemap provider. I have put it into a user control (the control will be used for similar, but not always identical, functionality). The treeview...
0
by: krissco | last post by:
Hello Group, I was having the same issue as described here:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.