treeview source code

Upload: drio-rio

Post on 02-Jun-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 TreeView Source Code

    1/2

    // The code below will generically handle and size// TreeView, programmatically determining and indicating the label text// and whether the item is a "folder" level or a discrete item.

    // It is designed to be triggered from a button because that's what I// was trying to do in the first place.

    // Not much in code comments, I realize, but I'm just to bushed to do it// right now. If anyone would find a detailed explanation of WHY this// works, let me know and I'll be happy to put something together when I// get a chance.

    // Bob Riopel //-------------------------------------------------------------------------

    dbox "TreeView" toolbox init do tree_array = { {"Accounting", { {"John Smith", { {"Computer 432",},

    {"Desk 4454"},{"Chair 555"}

    }},

    {"Jane Jones", { {"Computer 432",},{"Computer 654",},{"Desk 4454"},{"Chair 555"}

    }}}}, {"Marketing", { {"Patricia Jackson", { {"Computer 444",},

    {"Printer 433654"},{"Scanner 53355"},

    {"Chair 232"}}}, {"Geoff Bean", {

    {"Computer 432",},{"Computer 654",},{"Desk 4454"},{"Chair 555"}

    }}}}} enditem

    Tree View 6, 4, 28, 10 Prompt: "Tree: " List: tree_array Variables: tree_idx, tree_status, tree_states

    Button "Show Variables" 12, 15, 15 do ShowArray({tree_idx, tree_status, tree_states})

    EndItem

    Text 6, 16.5 Variable: "Click Show Variables to show the tree variables:" Text same, after Variable: "The first array element shows the chosen item" Text same, after Variable: "The second array element contains 1 if you double-clicked" Text same, after Variable: " on an item or clicked to expand or collapse an item" Text same, after Variable: "The third array element the shows open/close states of"

  • 8/11/2019 TreeView Source Code

    2/2

    Text same, after Variable: " the tree (1 = open, 0 = closed, null = no subtree)"

    Text 40, 1, 25 Variable: "GISDK Code to Create Item" Text 40, after, 38 Variable: "--------------------------------------------------------------------"

    Text 40, 4 Variable: 'Tree View 6, 4, 28, 10 Prompt: "Tree: "' Text 40, after Variable: "List: tree_array " Text 40, after Variable: "Variables: tree_idx, tree_status, tree_states"

    // Add a button Button "[Try THIS one!]" 50, 10, 15, 2.5 Key: Alt_U do //Only bother if something is selected if tree_idx.length > 0 then do

    // Set up working copies of the tree_array and tree_states myStateArray = CopyArray(tree_states) prevNode = CopyArray(tree_array) myNode = null

    for i = 1 to tree_idx.length do tmpIndex = 2

    If i = tree_idx.length then tmpIndex = 1 myNode = prevNode[tree_idx[i]][tmpIndex] If tmpIndex = 2 then prevNode = CopyArray(myNode) tmpStateArray = SubArray(myStateArray,tree_idx[i],1) myStateArray = CopyArray(tmpStateArray[1][2]) end // for If myStateArray = null then

    myMessage = "Bingo! You selected: " + myNode else myMessage = "Sorry, " + myNode + " is not an Item!" end // if...do showmessage(myMessage)

    // How do get rid of variables and arrays no longer needed? myNode = null prevNode = null tmpStateArray = null myMessage = null tmpIndex = null

    EndItem

    // Enable the close box on the title bar Close do Return() endItem

    // That is all!endDbox//-------------------------------------------------------------------------