Question Treeview - Get Checked Node...

Goldfish

Registered User.
Local time
Today, 08:37
Joined
Sep 24, 2013
Messages
14
Hi there

This may be an elementary question, but Googling I just can't find the answer I'm looking for; and I used to be able to find my way around the MSDN library but I can't seem to find anything in there today (bad cold, suffering :().

Anyway, I have a TreeView on a form.

The TreeView Nodes are all 'Check'able items (.Checkboxes = True).

When the user Checks/Un-Checks a Parent node I want the Child Nodes to also be Checked/Un-Checked.

I'm assuming I have to do this via VBA, as I couldn't see an option to do this automatically via property configuration.

My question is:
How do I determine which Node has been Checked/Un-Checked?

From within the Treeview_Click Event I can get at the Selected Node (Treeview.SelectedItem), but the Selected Node may not be the Node that was Checked/Un-Checked.


Thanks for all replies in advance.

:)
 
You'll want to handle the NodeCheck() event instead of Click(). The NodeCheck event provides a reference to the checked node.
 
Thanks MarkK

I've looked that Event up (msdn.microsoft.com / en-us/library/aa443082(v=vs.60) .aspx) and set the Event subroutine in my code as:

Private Sub MyTreeView_NodeCheck(ByVal Node As MSComctlLib.Node)

End Sub


However, when loading the form Access pops up an error dialog with a message:
"The expression On Load you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name"

Now, I know that I must have done something wrong, but not able to figure out what - the documentation for these TreeViews is a little sketchy...


Any ideas?

Many thanks
 
Its OK - figured it out now, it should read:

Private Sub MyTreeView_NodeCheck(ByVal Node As Object)

End Sub


NOT

Private Sub MyTreeView_NodeCheck(ByVal Node As MSComctlLib.Node)

End Sub


Looks like I read the MSDN page wrong, although to me it is misleading.
 
In order to host an MSComCtlLib object Access wraps it in a control called a CustomControl, and the object itself is exposed by the Object property. But that is not strongly typed, and doesn't show intellisense, for instance. What I commonly do is declare my own WithEvents variable in the form or report, and assign to it the object in the control, but consider this code, it's clearer . . .

Code:
[COLOR="Green"]' declare WithEvents Treeview variable global to the form[/COLOR]
Private WithEvents m_tvw as MSComCtlLib.Treeview

Private Sub Form_Open(Cancel As Integer)
[COLOR="Green"]'  the treeview is the Object in the control, so here we assign it 
'  to our m_tvw variable.  [/COLOR]
   Set m_tvw = Me.Treeview0.Object
End Sub
So now when the form opens we have a live, strongly typed instance of the MSComCtlLib object, which shows intellisense, and it appears in the (General) combo at the top of your code window. Select it there and then in the (Declarations) combo you'll find all the events that object raises, and click one of those and it writes the event handler stub automatically.
 
Thanks MarkK, that's interesting - looks like a good idea to implement.

Thanks again

:)
 

Users who are viewing this thread

Back
Top Bottom