LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Process Tree Control In Sort Order

I have a tree control which can be sorted at run time in multiple ways based on user input.  I need to be able to move through the list of items in sort order, not in index order.  As far as I can tell, there is no programming interface that allows me to do this.  For example, given a list of three numbers: 1, 2, and 3 with matching index numbers, sort them in random order (3->1->2), then begin with the "first" item and move down through the list from index 3 to index 1 to index 2.  I can't find a way to return the index of the first item in the list based on the sort order, or a way to advance to the next item.  The only thing I can think of is to use the GetIndexFromPoint function, starting with the upper left corner of the control, then adding the row height each time.  This is a terrible idea, but it's all I've got so far.  There must be an easier way. 
0 Kudos
Message 1 of 4
(3,120 Views)
A tree item's index is alway its current zero-based ordinal in the list. No matter how you sort a tree, index 0 will refer to the item at the top of the list, index 1 will refer to the next, and so on. Let me know if this doesn't answer your question, or if you have others.

Mert A.
National Instruments
0 Kudos
Message 2 of 4
(3,118 Views)

That's the behavior I expected, but it doesn't seem to work that way.  Here's a sample of how I'm trying  to advance the index to the next item in the list:

int ItemIndex;

GetCtrlVal(panelHandle, controlHandle, &ItemIndex);

if (++ItemIndex == NUMBER_OF_ITEMS) ItemIndex = 0;

SetCtrlVal(panelHandle, controlHandle, ItemIndex);

Maybe my assumption that the Get/Set functions operate on the index is incorrect?

0 Kudos
Message 3 of 4
(3,114 Views)

Nevermind!

I switched to GetCtrlIndex and SetCtrlIndex and it works as expected.  Maybe next time I should pay more attention to the documentation (duh).

0 Kudos
Message 4 of 4
(3,099 Views)