Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Treeview
Message
From
20/05/2010 07:08:00
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
19/05/2010 16:59:23
Issam Mansour
Jordan Business Machines
Amman, Jordan
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01465171
Message ID:
01465245
Views:
74
>Hi,
>
>How to search a treeview to change the checked status on a multi level treeview example:-
>A
>--A1
>---A1A1
>--A1A2
>--A2
>---A2A1
>--A2A2
>B
>
>WHEN I CLICK THE A NODE HOW TO CHECK OUT ALL THE NODES BELONG TO THAT NODE.
*NodeCheck event
    lparameters node
    llChecked = node.Checked
    this.CheckSubNodes(node, m.llChecked)

*  procedure CheckSubNodes
    lparameters toNode, tlChecked
    local loChildNode
    if toNode.Children > 0
      loChildNode = toNode.child
      do while vartype( loChildNode ) = 'O'
        loChildNode.Checked = m.tlChecked
        this.CheckSubNodes( loChildNode, m.tlChecked )
        loChildNode = loChildNode.next
      enddo
    endif
Here is a sample:
#Define tvwFirst	0
#Define tvwLast	1
#Define tvwNext	2
#Define tvwPrevious	3
#Define tvwChild	4

Create Cursor myNodes (nodeID i, parentID i, nodeText c(20))
Insert Into myNodes Values (1,0,"Root 1")
Insert Into myNodes Values (2,0,"Root 2")
Insert Into myNodes Values (3,0,"Root 3")

Insert Into myNodes Values (4,1,"Root 1-C1")
Insert Into myNodes Values (5,1,"Root 1-C2")
Insert Into myNodes Values (6,1,"Root 1-C3")

Insert Into myNodes Values (7,2,"Root 2-C1")
Insert Into myNodes Values (8,2,"Root 2-C2")
Insert Into myNodes Values (9,2,"Root 2-C3")

Insert Into myNodes Values (10,4,"C1-C1")
Insert Into myNodes Values (11,4,"C1-C2")
Insert Into myNodes Values (12,4,"C1-C3")
Insert Into myNodes Values (13,4,"C1-C4")

Insert Into myNodes Values (14,10,"C1-C1-C1")
Insert Into myNodes Values (15,10,"C1-C1-C1")

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

Define Class myForm As Form
  Add Object Tree As myTreeView

  Procedure Init
    With This.Tree
      .Width = This.Width
      .Height = This.Height
      .Anchor = 15
      Select myNodes
      Scan
        If parentID = 0
          .Nodes.Add(,tvwFirst,Padl(nodeID,3,'_'),nodeText)
        Else
          .Nodes.Add(Padl(parentID,3,'_'),tvwChild,Padl(nodeID,3,'_'),nodeText)
        Endif
      Endscan
    Endwith
  Endproc
Enddefine

Define Class myTreeView As  OleControl OlePublic
  OleClass='MSComCtlLib.TreeCtrl'

  Procedure Init
    With This
      .linestyle = 1
      .indentation = 5
      .PathSeparator = '\'
      .CheckBoxes = .T.
    Endwith
  Endproc

  Procedure NodeCheck
    Lparameters Node
    llChecked = Node.Checked
    This.CheckSubNodes(Node, m.llChecked)
  Endproc

  Procedure CheckSubNodes
    Lparameters toNode, tlChecked
    Local loChildNode
    If toNode.Children > 0
      loChildNode = toNode.Child
      Do While Vartype( loChildNode ) = 'O'
        loChildNode.Checked = m.tlChecked
        This.CheckSubNodes( loChildNode, m.tlChecked )
        loChildNode = loChildNode.Next
      Enddo
    Endif
  Endproc
Enddefine
PS: You can find documentation and sample code download in first issue of UT Magazine.
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
Next
Reply
Map
View

Click here to load this message in the networking platform