473,574 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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|K eyboard|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 8403
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|K eyboard|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?
--
PeteCresswel l


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.
--
PeteCresswel l

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.Ke ypreview 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?
--
PeteCresswel l

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 Recognized Expert Moderator Top Contributor
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
4397
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
3080
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 void Page_Load(object sender, System.EventArgs e) { Page.RegisterHiddenField("__EVENTTARGET","SomeButtonOnThePage");
2
1349
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 click on the plus sign however, the selected index doesn't change so I can't capture the index of the newly expanded node. Does any one know how to...
5
3115
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 click event will fire and the page will submit. I have a series of pages with Previous and Next navigational Btns. The Previous button is the...
2
1443
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 'reports' but the second level would not be menu items for each report but rather a treeview control which, when clicked, would produce the appropriate...
0
1091
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 be set <%@ Page Language="VB" EnableViewStateMac="True" Debug="true"AutoEventWireUp="true" %>
2
1568
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 to create my own control that would include capabilities of both treeview and Grid what would I have to do? Being new to asp.net I guess I've to make...
0
1469
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 expresses the hierarchy of sections in my website. In a page that edits sections, I would like to use the treeview to allow the user to select a parent...
0
1171
by: krissco | last post by:
Hello Group, I was having the same issue as described here: http://groups.google.com/group/comp.databases.ms-access/browse_thread/thread/4cb8b9fdc4c107ec/8d6da68840ec0ae9?lnk=gst&q=treeview+%22capture+enter%22#8d6da68840ec0ae9 I just realized a solution to this issue: Place a button on the form. Set the "Default" property of the button...
0
7813
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7736
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8066
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7826
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8106
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6461
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5305
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3755
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2251
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.