PDA

Click to See Complete Forum and Search --> : Treeview control


christophe
Nov 18th, 1999, 08:34 PM
Hi,

I'm new to using the Treeview control, part of the Windows Common Controls that you find in Project/Components.

When I add the Treeview control to my form I see 'Sample node' with Windows Explorer like indents, in the control in Design time. But when I run the program, there's no text in the control at all. Could someone tell me how I can make the text appear in run-time, and how I can edit the text?

Thanks!

Serge
Nov 18th, 1999, 08:42 PM
Sure! In disign time it just shows you how the control looks like, but it is up to you to populate the control.
Here is an example:



Dim xParent As Node 'Parent Node
Dim xChild As Node 'Child Node
Dim i As Integer 'Counter for parent Nodes
Dim j As Integer 'Counter for Child nodes

With TreeView1
.LineStyle = tvwRootLines
.Indentation = 300
For i = 1 To 5
Set xParent = .Nodes.Add(, , "Parent" & i, "Parent" & i)
For j = 1 To 10
Set xChild = .Nodes.Add(xParent, tvwChild, , "Child" & i & " to node " & xParent.Text)
Next
Next
End With




Look in the MSDN library for Node object. It will tell you what it is and how to work with it.
------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)


[This message has been edited by Serge (edited 11-19-1999).]

christophe
Nov 19th, 1999, 02:37 AM
Thanks for the reply, Serge.

But I cut and paste the code you give me, and in run-time, I still can't see anything. I didn't change any properties - am I supposed to?

Here's my exact code:

Dim xParent As Node 'Parent Node
Dim xChild As Node 'Child Node
Dim i As Integer 'Counter for parent Nodes
Dim j As Integer 'Counter for Child nodes



Private Sub TreeView1_BeforeLabelEdit(Cancel As Integer)
With TreeView1
.LineStyle = tvwRootLines
.Indentation = 300
For i = 1 To 5
Set xParent = .Nodes.Add(, , "Parent" & i, "Parent" & i)
For j = 1 To 10
Set xChild = .Nodes.Add(xParent, tvwChild, , "Child" & i & " to node " & xParent.Text)
Next
Next
End With
End Sub

Am I doing something wrong?

Christophe

Serge
Nov 20th, 1999, 03:40 AM
You pasted to the wrong event. Change it to Form_Load event.

Regards,

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)