From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I track the changes after SortTableCells()?

Running SortTableCells() by column key, and passing to it an user defined sort function, how can I track item-row changes? 
I mean: row 1 went to row 5, row 2 went to 4, and so on.
My application update a table control in real time, so I need to know (efficiently and fast) the new row of an item after sorted.
I try making my own sort function in ordem to tack the item changes and pass it to the SortTableCells() but a failure because I don't know how LabWindows implement  the quick sort algorithm.  Anorther problem is that the parameters item1 and item2 received by this user defined sort function always refer to the original position, (not the changed position) up to the end of SortTableCells() .
Can some one help me,
 
Thanks,
 
 
Guilherme
0 Kudos
Message 1 of 4
(2,942 Views)

Probably the easiest and quickest way to track down changes is to add a column with a progressive index filled up while writing to the table and sorted together with the rest of it: the content of this column will always show the original position of the row regardless of sorting.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(2,930 Views)
Guilherme,

Roberto's suggestion is a good one. The best way to handle this is to record the original row index of each cell in the table itself, so that after it is sorted, you can figure out where that row was before.

However, if you cannot afford to have an additional column, there is another trick you can use. You can take advantage of the fact that each cell can simultaneously hold 3 types of value: numeric, text, and picture. I'm not sure what type of data you are storing in your cells. Let's say it's numeric data. What you can do in that case is the following: temporarily change the cell type of each cell from numeric to string. Then set its value to the text representation of the row index ("1", "2", ...). Then change the cell back to numeric. The user will not see the text values at all, but they're still there. Then, after the table is sorted you can repeat the process, but instead of setting the values again, you read them, to find out what the original index of each cell was.

Boa sorte!

Luis
0 Kudos
Message 3 of 4
(2,926 Views)

Thanks, Luis and Roberto.

This is exactly I was looking for. A way to set data index before sorting and then retrieve it after sorting.

I didn´t know that table cells could hold 3 types of data simultaneously. And fortunately my data types are always character strings so it was easy to set my data index.

The problem was solved thanks to you,

 

Guilherme Venticinque

 

 

0 Kudos
Message 4 of 4
(2,896 Views)