Search code examples
labview

In LabVIEW, how can we programmatically construct a tree control which has only Left Cell Strings with different names and tags?


I have data that looks like in the below image. In this case, I manually added the items in the tree.

enter image description here

Also, each item in the tree has a unique tag associated with it.

enter image description here

I can do this manually, but when I am trying to do the same using the 'Edit Tree Item.Add Item' method from the Invoke node, it looks like:

enter image description here

I am attaching the vi that I used for this. Please take a look and let me know how I can make it work.

Tree_Construct.vi

Thanks


Solution

  • EDIT: Now with Labview code

    In a tree, each entry has a tag, and is linked to a parent entry by the tag of the parent. That is: Element1 is a child of Project, and Project is the parent of Element1. Likewise, Element1 is the parent of Subelement1 and Subelement2. And Project? It is on the root level, and has no parent, so its parent tag is empty.

    There are two ways to fill the tree:

    EditTreeItem.AddItem

    This node has inputs ChildTag and ParentTag. If ParentTag is empty/not connected, the item is placed on the root level. Use ParentTag to link an entry below another.

    Pro:

    • Appending a new entry below any existing entry is easy as long as you know the tag of the existing entry.

    Con:

    • Tree is updated after each call, makes execution very slow for many entries. Use DeferPanelUpdates to make it faster.
    • lots of code if you already know indentation levels.

    EditTreeItem.AddMultibleItemsToEnd

    This node gets an array of items as input, which are inserted into the tree in the order they are in the array. Each of them has a numeric ItemIndent to control the structure of the tree.

    Pro:

    • Very fast
    • Best if you know indentation levels, and don't want to mess with tags

    Con:

    • Can only append entries to the end

    Here is an example snippet (you can drag the image into an empty LV blog diagram!) showing both methods:

    enter image description here