Collapsible and expandable list field
zryip theSlug
zryip.theslug at gmail.com
Fri Jul 18 12:32:47 EDT 2014
Hi Mark,
In DGH the properties palette is a datagrid with 1 level nodes.
I do not pretend this is the best or easiest way for accomplishing
this, but here is the code I'm using sucessfully in DGH to collapse
and expand a node in a datagrid.
command dg_TreeExpansionFromDG pTheDg, pTheIndex, pColNodeName,
pColChildName, pNodeValue, pColExpandedName, pIsDGHHelp
local tIndexesList, tData, theIndex, tNewData, tKey, tDataArray,
tDataSourceRef, tSavedScroll
put the dgData of pTheDg into tDataArray
if (tDataArray[pTheIndex][pColNodeName] is pNodeValue) then
## Close the node
if (tDataArray[pTheIndex][pColExpandedName]) then
put the dgVScroll of pTheDg into tSavedScroll
lock screen
send "SetDataOfIndex pTheIndex, pColExpandedName, false" to pTheDg
arrayLib_FindIndex tDataArray, pColNodeName, "=",
tDataArray[pTheIndex][pColChildName]
put the result into tIndexesList
send "DeleteIndex tIndexesList" to pTheDg
send "RefreshList" to pTheDg
set the dgVScroll of pTheDg to tSavedScroll
unlock screen
else
## Open the node
put "true" into tDataArray[pTheIndex][pColExpandedName]
put the dgVScroll of pTheDg into tSavedScroll
put the cDataSourceRef of pTheDg into tDataSourceRef
put the dgData of tDataSourceRef into tData
arrayLib_Find_Argument_Clear
arrayLib_Find_Argument_Add pColNodeName, "=",
tDataArray[pTheIndex][pColChildName]
if (pIsDGHHelp is not true) then
arrayLib_Find_Argument_Add "View" && the dgPropListView of
_definePropertiesBehavior(), "=", "X" -- DGH only
end if
arrayLib_FindIndexByArg tData
put the result into tIndexesList
put arrayLib_ExtractKey(tData, tIndexesList) into tNewData
put item 2 of the extents of tDataArray into theIndex
repeat for each key tKey in tNewData
add 1 to theIndex
put tNewData[tKey] into tDataArray[theIndex]
end repeat
lock screen
set the dgData of pTheDg to tDataArray
dispatch "SortDataByKey" to pTheDg with pColChildName,
"numeric", "ascending", false
set the dgVScroll of pTheDg to tSavedScroll
set the dgHilitedIndex of pTheDg to pTheIndex
unlock screen
end if
end if
end dg_TreeExpansionFromDG
And inside the datagrid column I have:
command TreeExpansion pTheIndex
send "dg_TreeExpansionFromDG" && the dgControl of me & comma &
pTheIndex & comma & "Parent" & comma & "ID" & comma & "0" & \
comma & "expanded" to the dgControl of me in 20 millisecs
end TreeExpansion
DGH is now open sources, so you can have easily a look in the other
handlers required.
The same code is used in the Excel Library documentation with a
datagrid form and nodes should be expanded and collapsed in a snap.
Best,
On Fri, Jul 18, 2014 at 7:20 AM, Mark <mfstuart at cox.net> wrote:
> I'd like to build a tree list style Datagrid or field control. But I'm stuck on finishing this.
> Yeah I know, buy one from the community, but I'd rather build my own.
>
> So far I've built the script that loads the tree list, that will have 3 levels/nodes from a SQLite database.
> The collapsible and expandable nodes will have a 16x16 png image at the beginning of the line which has already been imported into the stack and referenced using the imageSource option in the load script.
>
> So far, so good.
>
> But this is where I'm stuck. I don't know how to build the script to collapse and expand a node.
> Obviously when a node is collapsed or expanded, it has to "hide" or "show" all its child lines. The selected line could be a 1st level node, which has to collapse or expand the 2nd and 3rd levels.
> Again, the tree list is populated from a SQLite database.
> The lines without an image will be line types that call another script to load another Datagrid when the user clicks on it.
>
> I've scouted the forum and user list for a solution. I've also looked at the Dictionary stack scripts. They all seem way too complicated. I develop applications using other tools and they already have tree view list contols. So it's a easy-peasy to implement.
>
> I'd sure appreciate help with this.
>
> Thanx,
> Mark Stuart
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
--
Zryip TheSlug
http://www.aslugontheroad.com
More information about the use-livecode
mailing list