angelleynes
Programmer
Hello,
anyone has a sample of treeview control?
thanks!
anyone has a sample of treeview control?
thanks!
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
* The file RptMenus holds the options configured in the treeview
SELECT RptMenus
* This form allows the user to select whether the new option is above or below the currently selected item in the treeview.
* It returns the Key of the item the new item should appear under. If there are currently no items, it returns 0. If the user canceled the operation, it returns -1.
DO FORM forms\RptChoice WITH RptMenus.RptMenuId TO lnMenuParent
IF lnMenuParent >= 0
lnNewId = oPCs.NextId("RptMenus") && My routine to assign an ID
IF lnNewId > 0
INSERT INTO RptMenus (RptMenuId) VALUES (lnNewId)
ENDIF
* Store the parent ID in the table
replace MenuParent WITH lnMenuParent
IF EMPTY(lnMenuParent)
* This will become one of the top items in the treeview
thisform.oletreeviewRptMenu.Nodes.Add("TOP",4,"RM"+TRANSFORM(RptMenus.RptMenuId),'')
ELSE
thisform.oletreeviewRptMenu.Nodes.Add("RM"+TRANSFORM(lnMenuParent),4,"RM"+TRANSFORM(RptMenus.RptMenuId),'')
ENDIF
* Find the index for the newly added item, and make that the selected item
FOR lni = 1 TO thisform.oleTreeviewRptMenu.Nodes.Count
IF "RM"+TRANSFORM(RptMenus.RptMenuId) $ thisform.oleTreeviewRptMenu.Nodes[lni].Key
* Found the node
thisform.oleTreeviewRptMenu.Nodes[lni].Expanded = .T.
thisform.oleTreeviewRptMenu.selectedItem = thisform.oleTreeviewRptMenu.Nodes[lni]
EXIT
ENDIF
ENDFOR
* We now want them to enter the newly added item, so let them edit the node
thisform.oleTreeviewRptMenu.SetFocus()
thisform.oleTreeviewRptMenu.StartLabelEdit()
lnCurrentId = VAL(STRTRAN(thisform.oleTreeviewRptMenu.SelectedItem.Key,"RM",""))
SELECT RptMenuId ;
FROM RptMenus ;
WHERE MenuParent = lnCurrentId ;
INTO cursor TmpChildren
IF _tally > 0
MESSAGEBOX("This option has options below it and cannot be deleted.",64,"Option in use")
USE IN SELECT("TmpChildren")
RETURN
ENDIF
USE IN SELECT("TmpChildren")
IF MESSAGEBOX("Are you sure you want to delete "+ALLTRIM(thisform.oletreeviewRptMenu.selectedItem.Text)+"?",36,"Delete request") = 6
SELECT RptMenus
SET ORDER to RptMenuId
IF "RM"+TRANSFORM(RptMenuId) <> thisform.oleTreeviewRptMenu.SelectedItem.Key
SEEK lnCurrentId
ENDIF
IF "RM"+TRANSFORM(RptMenuId) = thisform.oleTreeviewRptMenu.SelectedItem.Key
* Delete it from the table
lnParentId = MenuParent
DELETE
SET ORDER to RptMenuId
SEEK lnParentId
* Remove it from the treeview
thisform.oleTreeviewRptMenu.Nodes.Remove(thisform.oleTreeviewRptMenu.selectedItem.Index)
thisform.Expandtreeview()
thisform.oleTreeviewRptMenu.Refresh()
ENDIF
ENDIF
do (_samples+"\solution\solution.app")
WITH THISFORM.oletreeview1
FOR z = 1 TO 5
STORE 'znode' + ALLTRIM(STR(z)) TO znode
.nodes.ADD(,,znode, znode)
FOR j = 1 TO 5
STORE 'jnode' + ALLTRIM(STR(j)) TO jnode
.nodes.ADD(znode, 4, znode + jnode , jnode)
FOR k = 1 TO 5
STORE 'knode' + ALLTRIM(STR(k)) TO knode
.nodes.ADD(znode + jnode, 4, znode + jnode + knode, knode)
FOR l = 1 TO 5
STORE 'lnode' + ALLTRIM(STR(l)) TO lnode
.nodes.ADD(znode + jnode + knode, 4, znode + jnode + knode + lnode, lnode)
NEXT
NEXT
NEXT
NEXT
ENDWITH
RETURN
This.nodes.remove(This.SelectedItem.Key)