LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

mutilple selection int tree

hi,

i am trying to get label name from the selected tree items.there are some 10 items in a tree, i am randomly selecting few items say, 1st,3rd,5th items. now i need get the selected 3 item name in an array.how can i proceed... with the below code i can read only one selected item name but i need multiple....

GetNumTreeItems (panelHandle, PANEL_TREE, VAL_ALL, 0, VAL_FIRST, VAL_NEXT_PLUS_SELF, 0, &noOfChild); for(i = 0; i < noOfChild; i ++) { GetTreeItemAttribute(panelHandle, PANEL_TREE, i, ATTR_SELECTED, &select); if(select) { GetTreeCellAttribute(panelHandle, PANEL_TREE, i, 0, ATTR_LABEL_TEXT, treelabel); }

Fmt(targetstr,"%f",testcaseno); }

 

0 Kudos
Message 1 of 5
(3,889 Views)

There is code in the example program \samples\userint\treemenu that does what you want.

 

Here is another snippet that would work:

 

    for (error = GetTreeItem(panel, ctrl, VAL_ALL, 0, VAL_FIRST, VAL_NEXT_PLUS_SELF, VAL_SELECTED, &index);
         index >= 0 && error >= 0;
         error = GetTreeItem(panel, ctrl, VAL_ALL, 0, index, VAL_NEXT, VAL_SELECTED, &index))
    {
        // do something with index
    }
 

 

Hope this helps,

 

- jared

0 Kudos
Message 2 of 5
(3,876 Views)
Hi Jared,
with the above code snipet, i can able to read only one item value in a tree. If i select item 1st,3rd & 4th in a tree, index returns values as 4 and takes the 4th value alone in the gettreeitem.it is not returing 1st and 3rd item value though it is selected in tree control.
To be more clear, i have shared my code in which if i select the above mentioned items in a tree, output needs to be "u have selected item1,item3,and item 4" but my code return only one item value which is selected at last.how can i proceed to set multiple items selected? in the attached picture, i have selected item1,3,4 and it return "u have selected item4" but i need "u have selected item1,3and 4"

#include <formatio.h> #include <userint.h> #include "Test.h" #include <cvirte.h> int parentHandle=0; int main (int argc, char *argv[]) { if (InitCVIRTE (0, argv, 0) == 0) return -1; /* out of memory */ parentHandle = LoadPanel(0,"Test.uir",PANEL); DisplayPanel(parentHandle); RunUserInterface(); return 0; } int CVICALLBACK btn_print (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int index;int error=0; char text[100]={'\0'}; char targetstring[260]; switch (event) { case EVENT_COMMIT: for(error = GetTreeItem(parentHandle, PANEL_TREE, VAL_ALL, 0, VAL_FIRST, VAL_NEXT_PLUS_SELF, VAL_SELECTED, &index); index >= 0&&error<=0;error = GetTreeItem(parentHandle, PANEL_TREE, VAL_ALL, 0, index, VAL_NEXT, VAL_SELECTED, &index)) { GetTreeCellAttribute(parentHandle, PANEL_TREE, index, 0, ATTR_LABEL_TEXT, text); Fmt(targetstring,"u have Selected %s",text); SetCtrlVal(parentHandle,PANEL_TEXTMSG,targetstring); } break; } return 0; } int CVICALLBACK btn_quit (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: QuitUserInterface(0); break; } return 0; }

 

0 Kudos
Message 3 of 5
(3,841 Views)

Thanks for attaching the picture.... The problem is that you are using the word "selected" when you mean "checked", or at least that is how I was understanding it. Selection means to be hilited in blue (like when you <ctrl> click, or <shift> click on items when the tree is in multiple selection mode).

 

From your picture, I see that you want to iterate thru the checked (or marked) items. To do that, change the instances of VAL_SELECTED to VAL_MARKED in your code. Also, if you change the text message control to a text box control, you'll be able to see the output of each iteration.

0 Kudos
Message 4 of 5
(3,809 Views)

Hi Jared,

It works well with VAL_MARKED!!!!

i was bit misconfused with VAL_MARKED and VAL_SELECTED.

thanks a lot for ur solution....

0 Kudos
Message 5 of 5
(3,786 Views)