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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a TreeView 1

Status
Not open for further replies.

dcroe05

Programmer
Feb 15, 2005
44
US
I'm trying to use a TreeView on a form. I get the Tree built just fine, but now I'm not sure I can do anything with the damn thing.

The only events I have available to me are Updated(not BeforeUpdate or AfterUpdate), GotFocus, LostFocus, Exit and Enter.

How do I open a record based on a selection in my Tree Control?
 
Store the ID of the record in the Key (or Tag) property of each node when populating the tree.

Then on the NodeClick event of the TreeView control interrogate the Node.Key or Node.Tag properties of the selected node and there you put your record open code.
 
You have many properties avaliable to you besides those you mention.
In the forms module window in the left drop down select the treeview object then in the right drop down it will expose the additional events you have available to you.
You can also press F2 to display object browser to expose the events as well.
 
wm2005 & gol4,

Thank you for your replies. I realize now I didn't ask exactly the right question, but you got me pointed in the right direction, and I've hade significant progress.

I'm actually almost finished with my treeview (I'm designing a DB for a friend to keep notes in about writing projects).

Here's the last hurdle:

I've got the tree built, and when you click on an appropriate node the corresponding record is displayed in a subform.

But now I need to make one final feature. If the title of the record in the subform changes, I need that to be reflected in the tree.

I know the Node.Text feature will let me do this, but I've had no luck using this unless I use the NodeClick event.

What's the syntax for referencing back to the Node?

I know this isn't the syntax but I think it explains my intention:

treeNotes.Node.Text = forms!subform.txtNote


Any help would be appreciated.






 
I had not seen this example but I had found a similar sample that helped me in some tricky spots. However, this sample has the same problem I have. If this example, if youedit the title of one of the books in the subform, the Node for that book becomed nonfunctional until you reopen the form.

What I want is for a change in the record to be reflected in the tree without rebuilding the tree.

Thanks for the page, though. There are some other samples on the page I think I'll be looking at.
 
Helen fedemma's sample has the same problem. I didn't research more on that may be later when I get time.

________________________________________
Zameer Abdulla
Visit Me
If you have never been hated by your child, you have never been a parent.
 
unless you are doing something in code to unselect the node then
Me!yourtree.Object.SelectedItem should be what you are looking for
 
Just as a follow up the code to do it in the example provided by Helen referred to by Zameer would be

Code:
Private Sub txtTitle_AfterUpdate()
Forms!frmTreeViewRecordSelector.Form.tvwBooks.SelectedItem.Text = Me!txtTitle.Text
End Sub


 
One final thing regarding TreeViews.......


On a subform I have created a new record and added a New Node under the appropriate parent.

Now how do I select that node through code?
 
Nevermind. I figured it out. I don't think you can do it directly. Instead you loop though the Nodes and Set the SelectedItem when you meet a condition.


For Each Node In Tree.Nodes
If (Node.Key = strKey) Then
Tree.SelectedItem = Node
Exit For
End If
Next
 
You can loop thru the nodes collection but you can also do it directly

Code:
Dim nodecurrent As Node
Set nodecurrent = xtree.Nodes.Add(, , key, text)
if nodecurrent = condition then do this
nodecurrent.ForeColor = IIf(xtree.Nodes.Count Mod 2, vbBlack, vbCyan)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top