LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read 'clicked header' AND selected row from multicolumn listbox?

I have a multicolumn listbox filled with 6 columns and about 500 rows.

I want the user to be able to click on a column header, and sort the listbox alphabetically on that column. I've written the code for that, and that works. (using the 'itemnames' en 'get clicked col hdr' properties.)

However, I also want to include the option, that when a user highlights a row, and then clicks on the header, that after the listbox gets sorted it scrolls down to the selected row.
(So that the user doesn't have to search for it)

And that's where things go wrong, because the value of the listbox changes to zero when you click on a column header. No I idea why it does that, but it's rather
annoying. Can I change that behaviour somehow?

Or any ideas how to get around it?
0 Kudos
Message 1 of 10
(4,223 Views)
Hi Anthony,

I think I found a solution to your problem.
I enclose a vi that does what you ask, it's a little complicated solution for a problem that appeared simple, but it's the only I found by now.
N.B. a delay in the while loop is necessary.

Regards,
Alberto Locatelli
0 Kudos
Message 2 of 10
(4,223 Views)
I don't think this will work for Anthony because after things are re-ordered, what was at row x may not be there anymore. So with your code, you will bring him back to the row he had selected, but not necessarily the row containing the data he had selected.

I think a sight modification to your code will work. Instead of storing the row number selected before header selection, store the contents of a cell on that row, then after sort, use another algorithim to find the row containing the cell value stored. One caveat, the cell you store should be from a column of unique values or you might find another row instead of the one you want. If you dont have a unique column, you could always append one.

BTW, Anthony, would you be interested in sharing your sorti
ng algorithim?

Jared
0 Kudos
Message 3 of 10
(4,223 Views)
Jared you're definitely right!
I was not considering that Anthony wants to sort the column.
The modification you suggest would fit it.
Anyway, I think Anthony's vi would look more 'friendly' if on the top or bottom of the listbox there is an array of booleans one for each column with the function of sorting/non-sorting the column items.
Of course it would be much easier either, but I don't know if Anthony likes it.
0 Kudos
Message 4 of 10
(4,223 Views)
Not sure if I want to include an array of booleans... The information in the rows is linked to each other, just like in a file list with size, date, comments etc.
In windows, the default way to sort such a list would be to click the corresponding header. If possible, I would like to do it the same way.

And the other reason to do it like this, is that this program is primairily about learning the new features in Labview 6. So I rather try to find solutions for problems, that hide from them. 😉

Anthony.
0 Kudos
Message 7 of 10
(4,223 Views)
My thanks to you and Jared.
Seems I got a working solution now.

Did take a while to figure out why your solution worked. Basicly, you're reading the row from a few iterations before.
As soon as I understood that, I simplified it a little. Look at the attached file... I think it does the same. 🙂


Jared asked for the sorting routine. As I don't seem to be able to attach files when replying to comments, I took the liberty to include it here also.

Basicly, I just use the 'sort 1D array' that comes with Labview 6. To be able to sort a 2D array, I convert every row to a cluster. That's something the 'sort 1D array' VI can handle nicely.
To sort on the correct column, I just cut all columns in front, and paste them behind again. A
fter sorting, I reverse the process.


Anthony.
Download All
0 Kudos
Message 8 of 10
(4,223 Views)
Thanks, Jared
0 Kudos
Message 10 of 10
(4,223 Views)
I do not know how you have implemented your sort but if
you make the sort in such a way that it outputs an array
of the original array indices, you can easily recover the new
index of the row.

If you have to sort an array of elements, input it in a for
loop that bundles the element with the loop index
e.g make a cluster {element,i}. Sort the outputed array of
clusters. You can recover the new index by looking
in the array for the previous index.


Jean-Pierre Drolet
Scientech R&D


"Anthony de Vries" a écrit dans le message news:
506500000008000000341A0000-986697009000@quiq.com...
> I have a multicolumn listbox filled with 6 columns and about 500 rows.
>
> I want the user to be able to click on a column header, and sort the
> listbox alphabetical
ly on that column. I've written the code for
> that, and that works. (using the 'itemnames' en 'get clicked col hdr'
> properties.)
>
> However, I also want to include the option, that when a user
> highlights a row, and then clicks on the header, that after the
> listbox gets sorted it scrolls down to the selected row.
> (So that the user doesn't have to search for it)
>
> And that's where things go wrong, because the value of the listbox
> changes to zero when you click on a column header. No I idea why it
> does that, but it's rather annoying. Can I change that behaviour
> somehow?
>
> Or any ideas how to get around it?
0 Kudos
Message 5 of 10
(4,223 Views)
Acutally, the sorting itself isn't the problem. It's getting the highlighted row when the header is clicked.

When I have the correct row, then I read the value from it, sort the array, and then search for the value again.
That means I do not get exactly back to the old position, but to the first match. However, that's exactly what I want.
0 Kudos
Message 6 of 10
(4,223 Views)
Then you simply have to write this value back to a listbox local.
This will highligth this value.

Jean-Pierre

"Anthony de Vries" a écrit dans le message news:
50650000000500000098220000-986697009000@quiq.com...
> Acutally, the sorting itself isn't the problem. It's getting the
> highlighted row when the header is clicked.
>
> When I have the correct row, then I read the value from it, sort the
> array, and then search for the value again.
> That means I do not get exactly back to the old position, but to the
> first match. However, that's exactly what I want.
0 Kudos
Message 9 of 10
(4,223 Views)