LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create an interactive mouse triggered table?

I'm trying to create a VI for an experiment that will take measurements from 3 GPIB devices and put them in a table, with the front panel roughly looking like the one attached (panel.jpg).  I'm trying to have the panel work as follows:

When the user hits the "Measure" button, the VI reads the devices and displays the values on top. I figured out that part. Now, once he/she is satisfied with the readings, he places the cursor in any cell in the table and presses "Write". This causes the 3 values to be written to 3 adjacent cells in that row, beginning with the cell clicked on. I'm not sure how to do that, though it probably needs a mouse event handler. Any ideas on how to do this? Thanks!

0 Kudos
Message 1 of 4
(3,833 Views)

A table is just a 2D array of strings, so to do random insertions, your string array needs to be the size of the table from the beginning. Initialize a 2D array of empty strings, then replace elements according to the cell position.

Attached is a simple demo (LabVIEW 8.0) that demonstrates how to fill a table cell whenever a cell is double-clicked. (notice that the table is a disabled indicator, so only programmatic changes can take place). You should be able to modify it for your needs to fill 3 adjacent cells. It may also need a few little tweaks in the coordinate handling.

If you like to fill on a button press, you would sense a single click and place the coordinates into a shift register, later to be read in the "write" event where you do the element replacements. modify as needed. There are many other ways to do this.

Note that all cells have the same size, else the problem would become a bit more complex. 😉

Message 2 of 4
(3,817 Views)
Thanks for the help. Actually, there's a method to replace a single cell value in a table. If you use the "Invoke Node" function from application control (or right click on table > Create > Invoke Node > Set Cell Value), you can set the cell value to your choice of string via it's Col/Row indices (SetCellValue.jpg). I happened to stumble on it completely by accident. The sample VI you gave was very helpful in obtaining the Row/Col of the active cell - thanks again!
Message 3 of 4
(3,793 Views)

Well, there are actually reasons for my suggestion. 😄 If performance is an issue, stay away from these nodes. 🙂

In a simple benchmark using a 10x10 table, your invoke node is 18x slower than my version (55 microseconds vs 3 microseconds (actually the array update only takes 100ns (550x faster!) if you don't update the terminal inside the loop e.g. if you need to update several cells at once).

Also, as expected, you still cannot write to cells that are outside the range of the 2D string array of the table.

It is also somewhat dangerous if the table is an indicator as in this case because the rest of the code might not be aware of the new value unless you e.g. resort to reading a local variable of the table. Keeping the table data in a shift register is again more efficient and avoids extra data copies. 😉

Message 4 of 4
(3,775 Views)