Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Treeview Help
Message
From
23/09/2005 07:33:06
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
23/09/2005 00:37:30
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows '98
Network:
Windows 98
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01052278
Message ID:
01052326
Views:
6
>Dear Experts
>
>I want to show data in Treeview look like this
>
>1+PAID UP CAPITAL
>1- Eric den Doop
>2- Cetin Basoz
>2+DIRECTOR'S ACCOUNTS
>1- Sergy
>1- Borislav Borissov
>3+RESERVES
>1- Profit & Loss b/f
>1- Profit & Loss last year
>
>and for data I have following table entitled "Tree"
>
>
>CREATE TABLE tree (node N(2),child n(2), detail c(50))
>INSERT INTO tree (node, child, detail) VALUES (1,0,"PAIDUP CAPITAL")
>INSERT INTO tree (node, child, detail) VALUES (1,1,"Eric den Doop")
>INSERT INTO tree (node, child, detail) VALUES (1,2,"Cetin Basoz")
>INSERT INTO tree (node, child, detail) VALUES (2,0,"DIRECTORS ACCOUNTS")
>INSERT INTO tree (node, child, detail) VALUES (2,1,"Sergy")
>INSERT INTO tree (node, child, detail) VALUES (2,2,"Borislav Borissov")
>INSERT INTO tree (node, child, detail) VALUES (3,0,"RESERVES")
>INSERT INTO tree (node, child, detail) VALUES (3,1,"Profit & Loss b/f")
>INSERT INTO tree (node, child, detail) VALUES (3,2,"Profit & Loss last year")
>
>
>What should be the source codes to fullfil the purpose?
>
>Please help

Tariq,
With your structure it's hard to handle a treeview. However still based on that structure:
Create cursor tree (Node N(2),Child N(2), detail c(50))
Insert Into tree (Node, Child, detail) Values (1,0,"PAIDUP CAPITAL")
Insert Into tree (Node, Child, detail) Values (1,1,"Eric den Doop")
Insert Into tree (Node, Child, detail) Values (1,2,"Cetin Basoz")
Insert Into tree (Node, Child, detail) Values (2,0,"DIRECTORS ACCOUNTS")
Insert Into tree (Node, Child, detail) Values (2,1,"Sergy")
Insert Into tree (Node, Child, detail) Values (2,2,"Borislav Borissov")
Insert Into tree (Node, Child, detail) Values (3,0,"RESERVES")
Insert Into tree (Node, Child, detail) Values (3,1,"Profit & Loss b/f")
Insert Into tree (Node, Child, detail) Values (3,2,"Profit & Loss last year")

* Convert to a UniqueNodeId, ParentId, NodeText style
Select ;
  '_'+Padl(Node,5,'0')+Padl(Child,5,'0') As NodeId,;
  Iif(Child=0,space(11),'_'+Padl(Node,5,'0')+Padl(0,5,'0')) As ParentId,;
  detail As NodeText ;
  from tree ;
  order By 1 ;
  into Cursor myTree

#Define tvwFirst	0
#Define tvwLast	1
#Define tvwNext	2
#Define tvwPrevious	3
#Define tvwChild	4

Public oForm
oForm = Createobject('myForm')
oForm.Show

Define Class myForm As Form
  Height = 300
  Width = 500
  DoCreate = .T.
  Caption = "TreeView - testpad"

  Add Object myTree As OleControl With ;
    Height = 300, ;
    Width = 500, ;
    OleClass = 'MSComCtlLib.TreeCtrl'

  *-- Fill the tree values
  Procedure filltree
    Lparameters tcAlias
    This.Show
    Select (m.tcAlias)
    With This.myTree.Nodes
      Scan
        If Empty(ParentID)
          .Add(,tvwFirst,NodeId,Trim(NodeText))
        Else
          .Add(ParentId,tvwChild,NodeId,Trim(NodeText))
        Endif
      Endscan
    Endwith
  Endproc

  Procedure Init
    With This.myTree
      .linestyle =1
      .labeledit =1
      .indentation = 5
      .PathSeparator = '\'
      .Scroll = .T.
      .OLEDragMode = 0
      .OLEDropMode = 0
    Endwith
    This.filltree('myTree')
  Endproc
Enddefine
A better structure is with unique keys per node, level and order fields to allow you later add new nodes in desired position. ie: With above code change part above "#Define tvwFirst" line:
Declare Integer UuidCreate In 'RPCRT4.dll' String @pguid
Declare Integer StringFromGUID2 In 'Ole32.dll' ;
  string rguid, String @lpsz, Integer cchMax
Local lcParentID
Create Cursor tree (NodeID c(38), ParentID c(38), detail c(50),nLevel i,nOrder i)

Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ;
  (GetGUID(),'',"PAIDUP CAPITAL",0,10)
* Add children of this node
lcParentID = tree.NodeID
Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ;
  (GetGUID(),m.lcParentID,"Eric den Doop",1,10)
Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ;
  (GetGUID(),m.lcParentID,"Cetin Basoz",1,20)

Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ;
  (GetGUID(),'',"DIRECTORS ACCOUNTS",0,10)
* Add children of this node
lcParentID = tree.NodeID
Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ;
  (GetGUID(),m.lcParentID,"Sergy",1,10)
Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ;
  (GetGUID(),m.lcParentID,"Borislav Borissov",1,20)

Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ;
  (GetGUID(),'',"RESERVES",0,10)
* Add children of this node
lcParentID = tree.NodeID
Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ;
  (GetGUID(),m.lcParentID,"Profit & Loss b/f",1,10)
Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ;
  (GetGUID(),m.lcParentID,"Profit & Loss last year",1,20)

Select NodeID,ParentID,detail As NodeText ;
	From tree ;
	Order By nLevel,nOrder ;
	Into Cursor myTree
PS:
Function GetGUID
  Local pguid,rguid
  pguid=Replicate(Chr(0),16)
  rguid=Replicate(Chr(0),80)
  UuidCreate(@pguid)
  StringFromGUID2(pguid,@rguid,40)
  Return Strconv(Left(rguid,76),6)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform