01-27-2023 05:13 AM
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!
Solved! Go to Solution.
01-27-2023 05:43 AM
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.
01-27-2023 05:55 AM - edited 01-27-2023 06:31 AM
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.
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...
01-27-2023 06:53 AM
@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?
01-27-2023 06:54 AM
@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.
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.
01-27-2023 07:06 AM - edited 01-27-2023 07:07 AM
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…
01-27-2023 07:39 AM
Do you mean to use the Listbox as a kind of "sorter control" (see the code)?
Great idea!
01-27-2023 08:56 AM
@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)
01-27-2023 10:18 AM
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.