Most Valuable Professional


View Jan Karel Pieterse's profile on LinkedIn subscribe to rss feed
Subscribe in a reader

Subscribe to our mailing list

* indicates required

File crashes Excel!!

Save my workbook!
The best tool for salvaging problematic workbooks.

Trainings

Excel VBA Masterclass (English)
Excel VBA for Financials (Dutch)

Third party tools

Speed up your file

FastExcel
The best tool to optimise your Excel model!

Repair your file

Stellar Phoenix Excel Repair
Best tool to repair corrupt Excel sheets and objects
Home > English site > Articles > Treeview control > Features

An MSForms (all VBA) treeview; Features

Performance

Realistically a VBA form with all the controls we need for each node can’t be expected to match that of the compiled original. Even so we are surprised at what has been possible, albeit with considerable tuning and refining. Light testing suggests 1000 to 2000 nodes is quite feasible even in a typical five year old laptop, depending on the configuration of the treeview.

Cosmetics

The original has a wide variety of features and functionality. We have tried to replicate most of these, and added a few features of our own.

Checkboxes

The common controls treeview has a checkboxes option so you can check nodes. We ensured our treeview has that too.

A picture says more than a thousand words, so:

Checkboxes are possible and work
Checkboxes are possible and work!

Expand/collapse boxes or icons

By default we draw a rectangle with a plus or minus characters as text to mimic the expand/collapse boxes. You can also opt for expand/collapse icons. We have bundled XP and Win7 style expander icons in the demo form or you can customize your own as you wish:

 Expander icons are provided
Icons as expand/collapse buttons

Lines

The treeview from the common controls lib always shows lines to indicate the structure. With ours it is optional to show lines. The choice might be for aesthetic reasons, however a very large treeview will load significantly faster without lines so that might be an overriding consideration.

Choose whether or not to show lines
Choose whether or not to show lines

Icons

Again, let's just look at the picture!

Icons can be added
You can add icons too!

If you are familiar with the ImageList control we have incorporated a similar approach. You can store your images in a (hidden) frame and pass a reference to the frame, just as you would pass a reference to an ImageList to the common controls treeview. However your icon images could be stored anywhere. As long as you can retrieve a “StdPicture” handle for each icon and add it to a “collection” that’s all we need.

Label formatting

Label formatting is available to you with code as simple as:

cNode.Bold = True
cNode.BackColor = RGB(255, 255, 220)    ' pale yellow
cNode.ForeColor = RGB(180, 0, 0)    ' dark red

Make sure you do not use code like:

cNode.Control.BackColor = RGB(255, 255, 220)    ' pale yellow

When you are building the set of nodes, the controls of the treeview have not yet been created (this is done when .Refresh is called). Using the properties the node class itself exposes ensures those are applied when the nodes are created. Only once the treeview is fully initialised and refreshed you can access the properties of the cNode.Control.

In addition, the treeview will automatically pick up the default font settings of its parent (frame) control, so controlling appearance of the treeview starts as easy as setting properties of the frame you'll use to host the treeview. I'll explain this on the next page.

Functionality

We've already implemented quite some functionality. Here is what you can do "out of the box":

Function Description

Collapsing and expanding

Clicking the expand/collapse buttons does as advertised: it expands or collapses the tree.

Navigation using mouse and keyboard

Navigation using mouse and keyboard works just like in the "old" treeview. Right and left arrow expand or collapse, up and down arrow move up or down the tree. Page-up and down just work.

Editing nodes

You can use F2 to edit a node. Double-clicking a node also puts it in edit mode. This option can be enabled or disabled by setting a property value.

Drag and drop

We're working on that.

Copying, moving (cutting) and pasting

Copy and move functions are built in, you can copy or move single nodes or entire branches. You can do that silently but we have also made it easy for you to trap user actions on the selected node, eg Ctrl-c, Ctrl-x, Ctrl-v. You can include your own code to validate the intended actions, eg only allow copy between similar levels, then instigate the copy or move.

Sort

An efficient sort routine has been devised especially for this treeview. Currently it only operates at a given node level, however options for sort order and text/binary are included.

Properties

There is quite a number of properties you can change. To give you an idea, some are listed below. There are more properties and methods, which are documented in the Excel download.

Property Description Remarks

Full Width

True: Node caption widths extend beyond the width of the treeview, makes for clear highlighting of the selected node and if backcolor's are applied.

False: label widths are 'autosized' to the text
If node icons are used an additional image control is created for use with 'full width'

A large tree using node icons will load faster if 'full width' is not applied.

Checkboxes

True: show checkboxes.
Press spacekey or click to change the value.

The check change event is trapped in the form, and the info label updated.

Allow Editing

User can manually edit the node.
Double click or press F2 on a selected node.

Key Enter to apply the edit or Esc to abort.

Show Lines

Whether or not to show lines may be a matter of aesthetics or needs depending on the tree.
Try experimenting with different indentation widths (see the spin button).

In a large tree start-up time will be considerably faster if lines are not shown.

Root button

True: the entire tree can be collapsed to the Root.
False: the tree can only be collapsed to the first level.

 

Expander icons

The expander buttons can be Labels with +/- characters toggled, or pairs of icons.
If icons are used the images must be available in the workbook, on a sheet or as in the demo hidden on the form.

The demo includes pseudo WinXP and Win7 Explorer type expander icons, but you can use any icons of your choice, or no icons.

Indentation

Default is 15 points

 

NodeHeight

The treeview already automatically adjusts its Node height to the Font size or checkbox size or Icon size, whichever is the larger.

It's probably best not to adjust Node height.

Font size

The font size and other default label properties are adopted from the parent frame.

Change at design time only.

RootNodes

The root nodes of the tree  

Nodes

All Nodes of your tree  

Methods

Method Description Remarks

ActivateNode

Activate a node based on the key.  

Copy

Copies the node put on the 'clipboard'  

Move

Move source node + children to destination node.  

NodesClear

Equivalent to Treeview.Nodes.Clear.  

NodeRemove

Remove Node, its children and grandchildren.  

Refresh

Adds and displays all the controls for the Treeview for the first time. ALso displays and repositions node controls as required.  

SetTreeExpansionLevel

Updates the expanded properties according to lLevel. Called recursively.

TerminateTree

Removes the treeview from memory. Must be called before your userform goes out of scope.

ScrollToView

Ensures the node passed to the method is scrolled into view.  

Events

Currently we have made available a limited set of events:

Event Descrription

Click event

Fires when you click any node.

Node check event

Fires when you click the checkbox of a node.

After label edit event

Fires after editing a label.

Key down event

Fires when you press a key. The demoform included in the sample project shows how to implement copy and paste.

Mouse events

All mouse events are pushed through using a single MouseEvents event.

Add your own events

It isn't hard to add your own events, e.g. it takes three steps to add a new event for a specific element of the tree:

  1. Add event to the clsNode class for the piece of the tree you need an event for, by using the dropdowns at the top of the code window. Make sure it then calls a Friend sub in the clsTreeView class.
  2. Add an Event declaration to the clsTreeView class (like shown above) and a friend sub that raises that event when called from clsNode.
  3. Add an event handler to your userform.

Next: using this treeview in your VBA project.

 


 


Comments

All comments about this page:


Comment by: Gill (2/28/2013 4:43:27 PM)

Great work guys! :)
I'm not sure if this is a bug or a deliberate design feature, but I notice that the "NodesClear" method also sets the "TreeControl" object to Nothing.
This caused my project to crash several times until I worked out what was going on... I clear out and redraw the treeview whenever a change is made so it would be good if you could clear out all the nodes whilst leaving everyting else intact.
I realise it's not too difficult to work round, but like a lot of people I'm a disciple of PED and my code borrows heavily from the "PETRAS" application, so I'm sure others will have the same problem!

 


Comment by: Jan Karel Pieterse (3/1/2013 3:36:15 PM)

Hi Gill,

Thanks for letting us know!
I agree that nodesclear should not be clearing the pointer to the treecontrol.

We'll update the code as soon as we can to overcome this.

 


Comment by: Salim (3/28/2013 9:15:51 AM)

Jan Karel Pieterse,

Your TreeView Control is really quite amazing. You really deserve an award for this. I just hope we could one day create a custom GridFlex Control. I just realised on the TreeView Control that when a node is already active, clicking on it the second time does not trigger the click event. Just to let you know.

Thanks & warm regards,
Salim T. S.

 


Comment by: Jan Karel Pieterse (3/28/2013 3:26:38 PM)

Hi Salim,

Thank you very much for your compliment!

 


Comment by: Greg Bakker (7/6/2013 5:35:48 PM)

Salim mentioned that "when a node is already active, clicking on it the second time does not trigger the click event". I ran into this behavior also and did some digging to see if I could change the behavior. It looks like Jan/Ben anticipated that people may want this functionality. In the clsNode.mctlControl_Click() event procedure there is a comment that says that if it is preferred that the click event is always raised to the form (even if the node was previously active) simply comment or remove this If/EndIf check.

--Greg Bakker

 


Comment by: Eugene (8/28/2013 12:48:38 PM)

Excellent work. Here is a recursive method that I found on a Microsoft site which shortens the code and works well in Access.

Option Compare Database
Private Sub Form_Load()
Const strTableQueryName = "Your_tbl _Name"
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset(strTableQueryName, dbOpenDynaset, dbReadOnly)
AddBranch rst:=rst, strPointerField:="Parent", strIDField:="Id", strTextField:="Description"
End Sub
'Recursive Procedure to add branches
Sub AddBranch(rst As Recordset, strPointerField As String, strIDField As String, strTextField As String, Optional varReportToID As Variant)
Dim nodCurrent As Node, objTree As TreeView
Dim strCriteria As String, strText As String, strKey As String
Dim nodParent As Node, bk As String
Set objTree = Me!xTree.Object
If IsMissing(varReportToID) Then ' Root Branch.
strCriteria = strPointerField & " Is Null"
Else ' Search for records pointing to parent.
strCriteria = BuildCriteria(strPointerField, _
rst.Fields(strPointerField).Type, "=" & varReportToID)
Set nodParent = objTree.Nodes("a" & varReportToID)
End If
' Find the first emp to report to the boss node.
rst.FindFirst strCriteria
Do Until rst.NoMatch
' Create a string with LastName.
strText = rst(strTextField)
strKey = "a" & rst(strIDField)
If Not IsMissing(varReportToID) Then 'add new node to the parent
Set nodCurrent = objTree.Nodes.Add(nodParent, tvwChild, strKey, strText)
Else    ' Add new node to the root.
Set nodCurrent = objTree.Nodes.Add(, , strKey, strText)
End If
' Save your place in the recordset so we can pass by ref for speed.
bk = rst.Bookmark
' Add employees who report to this node.
AddBranch rst, strPointerField, strIDField, strTextField, rst(strIDField)
rst.Bookmark = bk     ' Return to last place and continue search.
rst.FindNext strCriteria ' Find next employee.
Loop
End Sub

 


Comment by: Antonio (9/17/2013 10:52:57 PM)

Hi.

I would know if is possible to emulate a Selected property, or anycase, how can I highlight a node.

I've been working in a search procedure (outside your code), and if found, I nedd to highlight the founded node.

Many thanks for your great job.

Antonio.

Madrid (Spain)

 


Comment by: Jan Karel Pieterse (9/18/2013 10:11:09 AM)

Hi Antonio,

You can simply set the ActiveNode, as in:

Set mcTree.ActiveNode = MyFoundNode

 


Comment by: David Engle (2/1/2014 3:10:29 AM)

OMG! Thank you! I have been fighting with the treeview in A2007 for months trying to overcome the Windows 7 problem. Too many workstations to be able to spend that much time. I am adding you to the credits in the About window for the project. Thank You!

 


Comment by: Antoniu (3/28/2014 4:34:40 PM)

Hello Jan

I am trying to add DblClick for mcTree. I add the event but when I dbl click on node
Private Sub mcTree_DblClick(cNode As clsNode) thas not fire up

(Those are my steps):

go in clsTreeView on TreeControl activate DblClick
Private Sub TreeControl_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

End Sub

put on General - Declaration this line

Event DblClick(cNode As clsNode)

on userform I can see DblClick event

but it is not working

Please can you show me the correct steps? Thank you!

 


Comment by: Jan Karel Pieterse (3/28/2014 7:07:32 PM)

Hi Antoniu,

You also have to raise the couble_click event using RaiseEvent. You can check how it is done by tracking fdown how we implemented the Click event.

Start from the sub "Private Sub mctlControl_Click()" in clsNode.

In there you will find this line of code:

moTree.NodeClick Control, Me


which calls a routine in the clsTree class:

Friend Sub NodeClick(ByRef oCtl As MSForms.Control, ByRef cNode As clsNode)


In that sub we raise the event so it is exposed to the userform implementing the tree class:

RaiseEvent Click(cNode)

 


Comment by: Shah (10/18/2014 12:41:33 AM)

Hi,

I am trying to use the access version of the treeview. I see activatenode as a function in the documentation but not in the downloaded code.

I have set keys for all nodes in my tree. I just want to scroll to the one based on selection in other control. Is there other way to do this?

Thanks.

 


Comment by: Jan Karel Pieterse (10/18/2014 11:43:52 AM)

Hi Shah,

You can just set the ActiveNode of the tree to the node you need.

 


Comment by: shah (10/18/2014 2:42:32 PM)

Hi Jan,

I have created a tree with about 16000 nodes with unique keys based on the data that I have in a table. I have created the tree and displayed it in the form.

My desire is to scroll the tree to a specific node based on the key's value. I have not been able to figure out a way to find a node based on the key. So, the right side of the mctree.ActiveNode assignment is where I am having problem.

Hope this clarifies.

Thanks.

 


Comment by: TPhong (11/26/2014 10:20:22 AM)

Hi there,

I just want to say thank you.
You did a really great job.

TPhong

 


Comment by: cris (2/5/2015 12:42:31 AM)

Hi,

This is great.

I notice some strange behavior with the checkbox button :
if checked before the demo's launched, parent nodes are selected (besides childs). Anyway I could manage to produce the dump of all selected nodes or subnodes.


I'm looking for enhancement to display the nodes that comply with a text search (filter) : we could make successive search and keep "checked" the various checkboxes throughout the different searches. Is there any sample of this ?

Thx
Cris


 


Comment by: Jan Karel Pieterse (2/5/2015 6:53:07 AM)

Hi Cris,

I'm afraid there is no sample for that. The checking of parent nodes depends on whether you have tristate set or not.

 


Comment by: Mathias (2/23/2015 6:02:32 PM)

I like your msforms treeview and i would like to have a treeview without a root because i want all items to be positioned directly under each other (without lines and without Expanders. Could someone help me by usin the code odf the demo-form (cmdgetdata) how this could be solved?

Thank you

 


Comment by: Jan Karel Pieterse (2/24/2015 6:22:12 AM)

Hi Matthias,

Peter Thornton said:

Hi Mathias,
If I understand your question you only want a single column of nodes, if so
maybe a ListBox or ListView would be more appropriate. However you can add
each node as a root node but with no child nodes and that will create a
column of nodes, adapt Sub InitializeDemo1 in the demo


' demo code
With mcTree
' demo code
    .ShowLines = False ' Me.cbxShowlines.Value
    .Indentation = 0
    For k = 1 To 50    ' # roots
        Set cRoot = .AddRoot(sKey:="Root" & k, vCaption:="My Node" & k)
    ' add or change any cRoot properties as required here
    ' comment all the demo code from here until Next
     Next
        
     'create the node controls and display the tree
     .Refresh
End With


Adapt other properties for the treeview as required, eg .FullWidth. Each
(root) node could have a different icon.

 


Comment by: mathias (2/24/2015 12:20:04 PM)

Hi Peter,
thank you for your prompt answer.

I use the folllwong code to get a treeview with no expanders.

        
'         Add a Root node with main and expanded icons and make it bold
    Set cRoot = .AddRoot("Root", "", "FolderClosed", "FolderOpen")
'
            
            
        Set dbs = CurrentDb
        ' Open recordset that returns the unique dates from tblBusinessUnit
        strSQL = "SELECT BusinessUnit_ID, BusinessUnit FROM tblBusinessUnit"
        
    
        
        Set rst1 = dbs.OpenRecordset(strSQL, dbOpenForwardOnly)
        ' Loop through the Business Units
        Do While Not rst1.EOF
    
            ' Add node
            strKey = "B " & rst1!BusinessUnit_ID
            strCaption = "Business unit: " & rst1!BusinessUnit
            Set cNode1 = cRoot.AddChild(sKey:=strKey, vCaption:=strCaption)
            cNode1.Bold = True
            cNode1.Expanded = True


but i don't want a root Checkbox to be shown in the view. (can i load up a Picture here? Just to Show what i mean.)

Got any idea?

Thank you.

 


Comment by: Jan Karel Pieterse (2/24/2015 12:55:35 PM)

Hi Mathias,

Unfortunately I do not allow any attachments. You could upload one to skydrive and share a link as an alternative however.

 


Comment by: Mathias (2/24/2015 6:21:25 PM)

next try:

i managed to get a single column of nodes almost loke i wanted to.

I did it like this:

        strSQL = "SELECT BusinessUnit_ID, BusinessUnit FROM tblBusinessUnit"
                    
        Set rst1 = dbs.OpenRecordset(strSQL, dbOpenForwardOnly)
        ' Loop through the Business Units
        Do While Not rst1.EOF
            ' Add root
            strKey = "B " & rst1!BusinessUnit_ID
            strCaption = "Business unit: " & rst1!BusinessUnit
            Set cRoot = .AddRoot(sKey:=strKey, vCaption:=strCaption)
                
            
            ' Open recordset that returns the Main Categories for each BusinessUnit
            strSQL = "SELECT Zwischen_ID, MainCategories FROM tblZwischenBusiness WHERE BusinessUnit_ID=" & _
            rst1!BusinessUnit_ID & " ORDER BY MainCategories_ID"
            Set rst2 = dbs.OpenRecordset(strSQL, dbOpenForwardOnly)
            ' Loop through the maincategories
            Do While Not rst2.EOF
                 'Add Node
                strKey = "M" & rst2!Zwischen_ID
                strCaption = "Main Categorie: " & rst2!Maincategories
                Set cNode2 = .AddRoot(sKey:=strKey, vCaption:=strCaption)
                            
                ' Open recordset that returns the students for each class
                strSQL = "SELECT ZwischenSub_ID, Subcategories FROM tblZwischenSub WHERE Zwischen_ID=" & _
                rst2!Zwischen_ID & " ORDER BY ZwischenSub_ID"
                Set rst3 = dbs.OpenRecordset(strSQL, dbOpenForwardOnly)
                 'Loop through the subcategories
                Do While Not rst3.EOF
                cNode2.Expanded = True

 


Comment by: Peter Thornton (2/25/2015 3:19:32 PM)

Mathias, it's hard to recreate your code but it looks like you are adding a single column of root nodes as I suggested. Keep in mind Expanders and ShowLines are true by default, though not Checkboxes. If your cNode2 does not have any child nodes there is no need to do cNode2.Expanded = True (actually Expanded = True is default)

You say you've got it working almost as you want, in what way is it not quite as you want.

 


Comment by: Mathias (2/26/2015 10:05:00 AM)

Hi Peter,

in my code example: how can i get a node being underlined?.

Cnode2.underline=true


or
cnode2.font.underline=true


does not work.

Thanks

Mathias

 


Comment by: Jan Karel Pieterse (2/26/2015 10:08:18 AM)

Mathias:

Please end a piece of code with [/vb] instead of [vb]

 


Comment by: Jan Karel Pieterse (2/26/2015 10:10:00 AM)

Mathias:

Please end a piece of code with square bracket /vb square bracket (so include the slash)

 


Comment by: Peter Thornton (2/26/2015 12:43:10 PM)

Mathias, we didn't include a Node.Underline property but you can add it yourself. Search both classes for "Bold": if you don't use Bold simply Replace most* of the "Bold" with "Underline", otherwise copy* the Bold code* in both classes and adapt to Underline.

*note Bold is also used in Expanders, don't change or copy that near where you see "-" and "+" (only in clsTreeView).

Add comments so you can easily adapt the next version.

 


Comment by: Ian (4/4/2015 10:42:46 AM)

How do I return a collection of a nodes children. The nodes.children property seems to return nothing

 


Comment by: Jan Karel Pieterse (4/5/2015 3:06:05 PM)

Hi Ian,

You need the ChildNodes collection.

 


Comment by: Paco (5/6/2015 3:40:32 PM)

This is an amazing piece of ingenuity! Elegant, unpretentious, very clever. Thanks for sharing.

Would you release drag & drop functionality anytime soon?

Any chance you could consider multi-select?

Kindest regards!

 


Comment by: Jan Karel Pieterse (5/6/2015 4:20:47 PM)

Hi Paco,

Thank you!

Multi-select. Hmm. You can by enabling check boxes. You can check as many boxes as you like.

 


Comment by: Elissa (5/15/2015 2:33:01 AM)

Hi.
Looks fantastic!
2 Questions:
1. Can it read from tables and alter the icon based on the data in the table?
2. Can it then be clickable, so a form pulls up based on which record is clicked?
Thanks!

 


Comment by: Peter Thornton (5/18/2015 11:35:49 AM)

Hi Elissa,
You can trap events to respond to the newly selected node, then pass details of the node to your own routine that reads your table to return details about the applicable icon.

Since build 026 icons can be updated to nodes during run-time, see Treeview.ImageAdd and Node.ImageUpdate in the documentation (in the Excel demo). Also see the examples in the demo form to respond to mouse and keyboard events.

 


Comment by: Tom (9/15/2015 11:37:09 AM)

Hi gentleman,

I'm trying to unload / change icons during runtime, but this does not seem to work?

Let's say I create a treeview, based on the with Icons example
Initially the treeview nodes don't have Images (only root has default Image)

Then I'm processing some data and based on some assertion
In case not ok: cNode.ImageMain = "nok"
In case ok: cNode.ImageMain = "ok"
mcTree.Refresh to rebuild
This seems to work

Now the issue 1:
When 'resetting' I'd like to have No icons, so I run for root.Children a loop: cNode.ImageMain = ""
mcTree.Refresh
But the Images still there

Now the issue 1:
When 'changing' I'd like to have all to "nok" icons, so I run for root.Children a loop: cNode.ImageMain = "nok"
mcTree.Refresh
But the Images still there (the old asserted "ok")

So, how can I update without assining a new collection to the treeview?

Thanks for your help!

Tom

 


Comment by: Peter Thornton (9/22/2015 12:57:28 PM)

Tom, sorry for late reply only just seen your comment.

The option to change icons during runtime was added in build 026 with ImageAdd and ImageUpdate (see the documentation). However we didn't consider anyone would want to remove icons from individual nodes altogether!

Contact me privately and I'll send you a small fix which hopefully will meet your needs.

 


Comment by: Jon von der heyden (10/21/2015 11:03:07 AM)

Using this for the first time and loving it! That is all. :)

 


Comment by: Jan Karel Pieterse (10/21/2015 3:18:05 PM)

Hi Jon,

Glad you like it!

 


Comment by: Frank (1/20/2016 2:13:37 PM)

Hi there - thank you for this great component. With this I could replace the annoying activex treeview.

I have one question - I would like to open a data record according to which Root/node was clicked. As in root I have jobs and in the nodes I have services contained in the jobs I must know what was clicked (root or node) and maybe read the key from the root/node. Is that possible? Thanks for help!

 


Comment by: Jan Karel Pieterse (1/20/2016 3:05:44 PM)

Hi Frank,

If you implement the mcTree_Click event, the argument you get passed to you is the node you clicked:

Private Sub mcTree_Click(cNode As clsNode)
    Dim cChild as clsNode
    If Not cNode.ChildNodes Is Nothing Then
        For Each cChild In cNode.ChildNodes
            'Now do something with the childnode.
        Next
    End If
End Sub

 


Comment by: swapnil bhalerao (1/30/2017 12:14:31 PM)

Hello
I am working on similar tree view but I want multiple checkboxes for each node (at least three) each representing cell of three different columns, also if I checked 3-4 nodes it must show value from an associated cell from the columns for which particular checkbox has been checked.

C1 C2 C3 are Checkboxes for each node if I checked C1.1(Node1) & c1.2(Node2) also C1.3(Node3) (First checkbox of three different nodes) it should show the sum value ( First checkbox C1 is associated with column 1) after cmd button has been hit.

 


Comment by: Peter Thornton (1/31/2017 5:55:07 PM)

Hi bhalerao,
It would be possible to add multiple checkboxes for but far to much to show how here. Try and follow how icons and checkboxes are added, and increase the offsets to add to Nodes' Left property. Event handling in the node class, and referred to the main treeview class can be added similar to the existing single checkbox.

I don't really follow the second part of your question, but once your event handlers are in place you can include code in the main form's event handlers to apply the combinations you require.

 


Comment by: Pablo (2/15/2017 9:49:17 PM)

Hi, This is an awesome component, but I'm experiencing something really odd, when I try to add event handlers to a node click event I got the event is raised even when a key is pressed (e.g.: Enter, Arrow Up, etc)
Do you have any suggestions on how to solve this?

P/S: I'm working on an Access 2013 Database. I see the same behavior on your sample app as well.

 


Comment by: Peter Thornton (2/16/2017 1:37:11 PM)

Hi Pablo,
Indeed, the navigation keys will indirectly raise the click event, which means you can trap a node has been activated whether my mouse or keyboard. This 'by design' and consistent with equivalent app's.

If you want disable keyboard navigation comment the relevant key actions in TreeControl_KeyUp and _KeyDown.

If you want to allow keyboard navigation but not raise any click events, you would need to adapt quite a bit more. But are you really sure you want to do that!

 


Comment by: Pablo (2/17/2017 9:33:43 PM)

Hi Peter,
Thank you for your quick answer, indeed I'd like to use keys for navigation and only raise a click event only when pressed "Enter" rather than on every keystroke, I'm trying to use the TV as a menu, where you can click or press enter to open the desired form. I tried also trapping the _KeyUp event but for some (odd) reason the keycode for "Enter" is the same as the left-arrow.
I'd be grateful if you can point out where to make the changes you mentioned in this line: "allow keyboard navigation but not raise any click events"

Thanks!

 


Comment by: Peter Thornton (2/18/2017 11:06:05 AM)

Hi Pablo, OK I think I follow.

In TreeControl_KeyDown replace 3 instances of "Caption", 1 with 0
In the same event near the top, after "If KeyCode = vbKeyReturn" comment the If/Else/End if and replace with:
If Not moActiveNode Is Nothing Then
    RaiseEvent Click(moActiveNode) ' Enter will raise the click event
End If

Or, trap vbKeyReturn in the mcTree_KeyDown or KeyUp event in the main form.

FYI Enter in other treeviews expands or collapses a branch, like the left/right arrow keys, and explains the "odd" reason Enter morphed into an arrow!

 


Comment by: Ray Buckley (10/19/2017 12:31:03 PM)

Hello,
Are you supporting drag drop functionality yet
Thanks
Ray

 


Comment by: Peter Thornton (10/19/2017 5:16:41 PM)

Hi Ray,

Drag & drop is supported the 'pro' (see above) but it's not viable in the free version, at least not in the way we'd want to do it.

 


Have a question, comment or suggestion? Then please use this form.

If your question is not directly related to this web page, but rather a more general "How do I do this" Excel question, then I advise you to ask your question here: www.eileenslounge.com.

Please enter your name (required):

Your e-mail address (optional but if you want me to respond it helps!; will not be shown, nor be used to send you unsolicited information):

Your request or comment:

To post VBA code in your comment, use [VB] tags, like this: [VB]Code goes here[/VB].