LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DB Connectivity Toolkit and Tree Views

All,

 

I've been getting familiar with the DB Connectivity Toolkit and have successfully wrote queries against our SQL Server database and dumped it into an array which is below. I'd now like to try to get the Tree View to add these plant names but I can't seem to understand how it works.

 

Does anyone have a example like mine which they have successfully done this?

 

VISnippet.png

 

0 Kudos
Message 1 of 20
(4,907 Views)

Hi,

 

If you are asking how to dump the array into a tree control you can use the property nodes for the tree.  There are some good examples of this in the developer zone documents/shared code. 

 

You have to decide how to manage the parent child relationships for our data, not knowing how the data looks there is not much to be specific about.

 

 

 

 

-------
Mark Ramsdale
-------
0 Kudos
Message 2 of 20
(4,902 Views)

The data looks like this once queried out of the SQL Server:

 

Plant1

Plant2

Plant3

etc....

 

First I want to see if I can even attempt this since this is my first stab at a Tree View Control of any kind. Searching around the internet on a how-to on how to use the Labview Tree Control appears to be non-existiant. Got a link to the Developer Zone that talks about Tree Views or a good how-to?

0 Kudos
Message 3 of 20
(4,882 Views)

Eric,

 

Here's a few links that you might find useful.

 

https://forums.ni.com/t5/Example-Code/Tree-Control-Template-State-Machine-to-Populate-the-Tree-Contr...

https://forums.ni.com/t5/Example-Code/LabVIEW-Tree-Control-Save-and-Restore-the-Status-of-a-Heirarch...

https://forums.ni.com/t5/Example-Code/Only-View-a-Single-Branch-of-a-Tree-Control-at-a-Time/ta-p/349...

https://www.ni.com/docs/en-US/bundle/labview/page/creating-a-tree-control.html

 

All of these examples show some different uses of tree controls, hopefully this wil help you get a start and some more understanding on LabVIEW Tree Controls.

 

-Nick-

Nick C | Software Project Manager - LabVIEW Real-Time | National Instruments
0 Kudos
Message 4 of 20
(4,870 Views)

Here is what I have so far which is just putting in one level into my tree view control...pretty simple.

 

LVTreeControl.png

 

I am unsure why it rendered the TreeControl reference as Tree2 in the image, but this is not the case.

0 Kudos
Message 5 of 20
(4,847 Views)

OK guys, I give up. I'm hoping someone can nudge me in the right direction. How do I wire an array of values like this...

 

FrontPanel.png

 

 

 

 

...to the Edit Tree Items.Add Item method (and have it's children underneath the Plant name)?

 

LVTreeControl2.png

0 Kudos
Message 6 of 20
(4,842 Views)

OK, I've gotten a little farther now. I've noticed if I only place a ware to the Left Cell String, everything comes in at the top level which I don't want. But I'm stuck on how to make everything but the plant names child products? Like this.....

 

Plant1

        LineCode1

              ProductCode1

        LineCode2

              ProductCode2

 

Plant2

       LineCode1

               ProductCode1

       LineCode2

               ProductCode1

       etc....

 

 

0 Kudos
Message 7 of 20
(4,825 Views)

Eric,

 

Here's a quick example that should help you get your data to look like this

 

Front Panel Tree.JPG

 

The tricky part of writing this program is going to be programmatically determining when to create a new child/parent. You'll have to write some logic that looks at the elements in the array to determine if a tag has already been created for it.

 

Basic Tree Structure.png

 

As you can see I've used a for loop to programmatically add several elements under the same parent tag. Best of Luck!

 

The attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system, or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject to the Sample Code License Terms which can be found at: http://ni.com/samplecodelicense

 

-Nick-

Nick C | Software Project Manager - LabVIEW Real-Time | National Instruments
0 Kudos
Message 8 of 20
(4,820 Views)

Hi Nick,

 

I've gotten a little closer but I can't figure out how to compare what's been entered on the Tree to what is in the database and then determine WHERE in the tree it belongs. I took a stab at it but I get a blank node when the For Loops first run. I don't even know if the Match Regular Expression function is the correct function to call here.

 

Any ideas?

 

TreeHelp.png

0 Kudos
Message 9 of 20
(4,801 Views)

I would recommend using a simple Equal? function. Since the tags are being generated using information directly from the array and both data types are strings, this is the proper function to use.

 

You will need to come up with a strategy for how to compare the data currently in the tree with the data in the array. Or you could evaluate your array, break it apart and programmatically add items to the tree. Either way, keep in mind that every item still has a tag associated with it.

 

It is not very efficient to compare each data element with each tag already in the tree. Since your array seems to be pre sorted you could compare array elements in specific columns to one another looking for a change. When you have determined a change you will know which portion of the array belongs under the "Argentina" country tag, for example.

 

Currently you are comparing information from the array with the tags in the tree, but no matter the results you are still adding a new child to the tree under the top level parent. To determine where in the tree the piece of data should fall you need to specify a parent tag.

 

I hope this information is helpful.

 

-Nick-

Nick C | Software Project Manager - LabVIEW Real-Time | National Instruments
0 Kudos
Message 10 of 20
(4,792 Views)