LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reordering columns in a table/array during run time

Solved!
Go to solution

Hi all,

 

I'm building a program to read .csv data which can later be exported to an Excel template. The raw fils contain data of differet channels which I can sort in columns. Is there a way for the user to reorder the columns of the table (or array if that is easier) during run time before exporting to the excel sheet? For example, there are five channels and perhaps the user would like channel 4 data to be in the first column, channel 5 in the second column, etc. 

 

If that is possible, then it brings me to the second question: what would be a suitable method for the user to define the order of the columns? (checkbox, radio button??)

 

Reordering columns of data in the development environment is not a problem, but I'm not quite sure how to achieve this during run-time, especially if it's user-defined and not always the same columns.

 

Thank you in advance!

0 Kudos
Message 1 of 9
(2,617 Views)

There are multiple ways to achieve this, find few below

 

If you want more user friendly you can create menu item to move right or left and use Array functions.

Else you can get the Source Column Index and Destination Column Address to swap the data.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 2 of 9
(2,603 Views)

About the first question.

If the array size is huge, try this option.

But perhaps there are more "memory efficient" ways to swap columns of a 2D array.

ColSwap.png

About the second.
If it suits you that the columns and rows are swapped, then it will be convenient to use the MultiColumn Listbox for this.

Enable Drag&Drop in Listbox menu and you can swap rows simply by mouse. After this, you can read sorted values from Listbox by ItemNames node and export them.

 

Maybe it`s not what you need, but it quite simple for rows. Unfortunately you cant select and swap columns in LabVIEW MultiColumn Listbox...

0 Kudos
Message 3 of 9
(2,582 Views)

@PalanivelThiruvenkadam wrote:

There are multiple ways to achieve this, find few below

 

If you want more user friendly you can create menu item to move right or left and use Array functions.

Else you can get the Source Column Index and Destination Column Address to swap the data.


I'm sorry but I don't understand what you mean. What are the 'multiple ways' that you are referring to?

 


0 Kudos
Message 4 of 9
(2,556 Views)

@diman27 wrote:

About the first question.

If the array size is huge, try this option.

But perhaps there are more "memory efficient" ways to swap columns of a 2D array.

ColSwap.png

About the second.
If it suits you that the columns and rows are swapped, then it will be convenient to use the MultiColumn Listbox for this.

Enable Drag&Drop in Listbox menu and you can swap rows simply by mouse. After this, you can read sorted values from Listbox by ItemNames node and export them.

 

Maybe it`s not what you need, but it quite simple for rows. Unfortunately you cant select and swap columns in LabVIEW MultiColumn Listbox...


I don't want or need to swap rows and columns, just the order of the columns.

0 Kudos
Message 5 of 9
(2,554 Views)

Hi nikvl,

 


@nikvl wrote:

If that is possible, then it brings me to the second question: what would be a suitable method for the user to define the order of the columns? (checkbox, radio button??)


Sure it's possible!

Run a loop with inputs 2D-array and order of columns and use IndexArray inside the loop to pick the columns in the "order of columns"…

 

I suggest to use a listbox with drag&drop enabled with an item per column, so the user can easily sort the items in the listbox!

 

Btw. swapping columns is also changing the order of columns…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 9
(2,544 Views)
Solution
Accepted by topic author nikvl

Do you mean to use the Listbox as a kind of "sorter control" (see the code)?
Great idea!

0 Kudos
Message 7 of 9
(2,518 Views)

@GerdW wrote:

Hi nikvl,

 


@nikvl wrote:

If that is possible, then it brings me to the second question: what would be a suitable method for the user to define the order of the columns? (checkbox, radio button??)


Sure it's possible!

Run a loop with inputs 2D-array and order of columns and use IndexArray inside the loop to pick the columns in the "order of columns"…

 

I suggest to use a listbox with drag&drop enabled with an item per column, so the user can easily sort the items in the listbox!

 

Btw. swapping columns is also changing the order of columns…


Ah, I almost never use listboxes so I wasn't aware you could drag items in it. TIL

 

Yes, you're right about the swapping and I misunderstood the 'swap rows and columns' to be transposing, which probably wasn't what was being meant but more swap rows and columns respectively...so my bad. 

 

Do you mean to use the Listbox as a kind of "sorter control" (see the code)? Great idea!;

Thank you for the vi! It does solve my problem 🙂 

 

(Though I suppose it's too much to ask to make it more "UI-friendly": moving items sideways/horizontally instead of changing rows to denote order but listbox doesn't allow that. The other thing is that a listbox in general doesn't seem intuitive to a user who isn't a LabVIEW programmer that one could drag and move items around and not just for selection. In my head I pictured more a reorder function where numbers appear in a box next to item - similar to numbering when reordering items in a cluster) 

0 Kudos
Message 8 of 9
(2,497 Views)

As an option - a more "UI-friendly" version...

Right click on the required column. Select another column from the menu that you want to swap with.

Message 9 of 9
(2,450 Views)