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

TreeView is killing me. - help!!!

Status
Not open for further replies.

castor2003

Programmer
Jul 5, 2003
115
LC
I am trying to use this control for the first time and I was hoping the following code would display one root node with a child along with the + sign. Also, when I run the form it says that references are not complete and hangs up. What could by my problem?


Code:
#DEFINE relatFirst	0
#DEFINE relatlast	1
#DEFINE relatNext	2
#DEFINE relatPrev	3
#DEFINE relatChild	4

** DO LEVEL ONE NODES and Level2 dummies

PUBLIC oTree as OleControl
oTree = thisform.tview

** relative,relationship,key,ctext,image

PUBLIC ARRAY aLevel1(1,4)

	 aLevel1(1,1) = ""
	 aLevel1(1,2) = 1
	 aLevel1(1,3) = 'key'
	 aLevel1(1,4) = [Districts Not yet Defined]
	
** Will load level one real data here


FOR i = 1 TO ALEN(aLevel1,1)

	oTree.nodes.add(,aLevel1(i,2),aLevel1(i,3),aLevel1(i,4))

NEXT i


***Level 2 dummies

* will load level 2 data below 

PUBLIC ARRAY aLevel2(1,4)

FOR i = 1 TO ALEN(aLevel1,1)

	oTree.nodes.add('key',4,"KG7","Child1")

NEXT i
 
Castor,

The first thing I noticed is that in this line:

oTree.nodes.add('key',4,"KG7","Child1")

your third parameter (KG7) is going to be the same in every node. That won't work. This parameter is the unique key for the (child) node, and must be different for each item that you are adding.

I suggest you fix that, and report back if there is still a problem.

Mike


Mike Lewis
Edinburgh, Scotland
 
Mike,
I am aware of that. If you noticed, that part of the code is really one iteration. Try using this exact code in the init() of a form with 'tview' as the control name.

 
castor2003,

Try this and see what you get:

PUBLIC oForm
oForm = createobject("clstview")

oForm.show()

DEFINE CLASS clstview AS form

Top = 0
Left = 0
Height = 479
Width = 582
DoCreate = .T.
Caption = "Treeview Test"
Name = "form1"

ADD OBJECT tview AS oletreeview WITH ;
Top = 32, ;
Left = 20, ;
Height = 198, ;
Width = 336, ;
Name = "tview"

ADD OBJECT command1 AS commandbutton WITH ;
Top = 252, ;
Left = 252, ;
Height = 27, ;
Width = 84, ;
Caption = "Exit", ;
Name = "Command1"

PROCEDURE Init
ThisForm.tview.Nodes.Clear

#DEFINE relatFirst 0
#DEFINE relatlast 1
#DEFINE relatNext 2
#DEFINE relatPrev 3
#DEFINE relatChild 4

** DO LEVEL ONE NODES and Level2 dummies

PUBLIC oTree as OleControl
oTree = thisform.tview

** relative,relationship,key,ctext,image

PUBLIC ARRAY aLevel1(1,4)

aLevel1(1,1) = ""
aLevel1(1,2) = 1
aLevel1(1,3) = 'key'
aLevel1(1,4) = [Districts Not yet Defined]

** Will load level one real data here


FOR i = 1 TO ALEN(aLevel1,1)

oTree.nodes.add(,aLevel1(i,2),aLevel1(i,3),aLevel1(i,4))

NEXT i


***Level 2 dummies

* will load level 2 data below

PUBLIC ARRAY aLevel2(1,4)

FOR i = 1 TO ALEN(aLevel1,1)

oTree.nodes.add('key',4,"KG7","Child1")

NEXT i
ENDPROC

PROCEDURE command1.Click
thisform.RemoveObject("tview")
thisform.release
ENDPROC

ENDDEFINE

DEFINE CLASS oletreeview as OLECONTROL
OleClass = "MSComctlLib.TreeCtrl.2"
PROCEDURE Init
this.object.style = 6
this.object.LineStyle = 1
ENDPROC
ENDDEFINE



Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Two more issues.

Do I have to pay Microsoft to distribute Treeview?
Do you know whether Installshield registers the ocx?
How do I get images/icons next to the nodes?

I would happy if someone could assist me.
 
I just tried it and it worked. My problem is that I was not double clicking to expand the root node. Thanks.

I would be glad if you would assist with the issues I just raised.


 
Hello,

a) No, you don't have to pay
b) Yes, InstallShield registers the ocx - you can do this manually also - it's stored in mscomctl.ocx. Copy this file in System or System32 folder and run "regsvr32 mscomctl.ocx".
c) The images are stored in another control, found in the same ocx, named ImageList. Put this one on the form (it's invisible at runtime), right click it, go to the Images page, and insert them one by one. Make them 16x16 pixels.

In treeview's init:

This.ImageList = thisform.imagelistcontrol

After that you can start adding the nodes, setting the image parameter to the corresponding image's index in ImageList.

Hope this helps.

Grigore Dolghin
Class Software
Bucharest, Romania
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top