I'm not sure what you mean by "link the control source" nor do I know what you need by "i would like to know which parent node and child node is selected", however hopefully this will help ...
You already have the NodeClick event covered - see that parameter that is passed in
node
... that is the node that is selected. You can get the full path for that node e.g.
Debug.Print node.FullPath
could produce
Africa\Benin
To find the parent, use the Parent property of node, but be wary of the top-level nodes that do not have a parent...
If Not node.Parent Is Nothing Then
Debug.Print node.Parent
End If
Would give
Africa
Possibly the easiest way to see what is available is to put a breakpoint on the line
If node.Key = "Africa" Or node.Key = "Americas" Or node.Key = "Asia" _
Or node.Key = "Australasia" Or node.Key = "Europe" Then
and then right-click on the
node
variable and add it to the Watch Window. You'll be able to see all of the properties such as
FirstSibling
and
LastSibling
. Unfortunately the links in the official MS documentation tend to route you to the .NET TreeView documentation which doesn't always quite match up with versions available to Excel.
Other points to consider - you are missing
Option Explicit
at the top of your form module. You should always have this set (you can set it up your options so that it is included automatically)
- It's a good idea to describe how you have set up your workbook to help us get quickly to the problem. E.g. here I would have said
Quote:
"I have a workbook with two worksheets, on Sheet1 I have columns entitled "Africa", "Americas", "Asia", "Australasia" and "Europe". Under those column headers there are lists of countries in those continents. Sheet2 contains ....(whatever) but is not relevent to this question"