Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get treeview node to expand when there is code in the onclick?

Status
Not open for further replies.

HandyAndy

Technical User
Jun 26, 2001
13
GB
Hi again
i have finally got my treeview going but since i have put some code in the nodeclick event the branch does not expand. How do i get the node to expand?
HandyAndy
 
Hi again, Andy!
Congratulation!

Nodes are expanding by double click on node.

Also you can point style (red in the following example). Then lines will be contain plus like win explore.

Set nodX = trvTreeView.Nodes.Add(strParentKey, 4, strKey, strNodeText, strImageKey, "SELECTED")

You can expand nodes by command, too e.g.:
trvTreeView.Nodes(1).Expanded = True

in the procedure NodeClick you can do lot of actions: open forms, update tables make settings etc.

Example:
Private Sub trvTypeUnit_NodeClick(ByVal Node As Object)
Dim nodX As Node
dim strSQL as string

Set nodX = Node
strSQL = "SELECT MyTable.Parent_ID, MyTable.Relationship, MyTable.Function_ID, MyTable.Function_Name "
strFrom = "FROM MyTable "
strWhere = "WHERE MyTable.Function_ID='" & nodx.key& "'"

docmd.runsql strSQL

End Sub


Use the event

Example:
Private Sub trvTypeUnit_Collapse(ByVal Node As Object)
Dim nodX As Node

Set nodX = Me.trvTypeUnit.SelectedItem

do.........
'My advice: Write codes same codes of NodeClick for correct work of treeview
...........
..........
end sub[/b]

Look at treeview properties window (double click on treeview control). Change properties if it's needed.

Good luck!
Aivars

LOL My summer holidays will start next week! Hurah!
 
Thanks for your help although i cannot get the +/- like explore thing to work???

ive looked at the syntax for the add method and this is what i got:
Function Add(ByVal hRelativeItem As Variant, ByVal Relation As RelationConstants, ByVal Key As String, ByVal Text As String, Optional ByVal Image As Long=-1, Optional ByVal SelectedImage As Long=-1, Optional ByVal IntegralHeight As Long=1, Optional ByVal Bold As Boolean=False) As Long

i dont see an entry for style????
any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top