Example Code

Tree Control Template - State Machine to Populate the Tree Control and User Interface to Manipulate Items

Code and Documents

Attachment

Download All

Overview
This example shows the way to use the tree control based on state machine.

 


Description
The original project parsed a file, and added items to a tree control based on tags in the file. When adding a row to a tree control, it must adda the item in the left column as a string, and then add the items in the rest of the columns as a 1D array, where each array index represents the column. For file parsing program, it was useful to use a state machine architecture, where the first state store the left column string in a shift register, and the rest of the states added the remaining column items to the correct place in the array. This array was also stored in a shift register to be accessed in multiple states. In the final state, the left column string was writen to the Left Cell String parameter of the Edit Tree Items.Add Item Invoke Node of the tree control, and the column data array was written to the Child Text parameter. See the screenshot below. The child position of -1 indicates that the item will be added to the bottom of the tree. Finally, the last state also reset the left cell string and child text array, so that a new row could be added.

Note: the current example is simplified so that it does not parse a file. Instead, it uses dummy data. The Tree Write vi is called from the top-level Tree Example vi, which is the user interface for the tree program. The user interface lets you move items from the top list (the library) to the lower list (the selected book list). You can also clear the library and rebuild the library, and manipulate the items in the selected book list.

 


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Download and unzip the attached folder to your computer
  2. Open the project "Tree Example 2012 NIVerified.lvproj"
  3. Open the VI "Tree Example.vi"
  4. Run the VI

 

Additional Information or References
VI Block Diagram of "Tree Example.vi"

 Block Diagram.PNG

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Julianne K
Systems Engineer, Embedded Systems
Certified LabVIEW Architect, Certified LabVIEW Embedded Systems Developer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.