05-13-2010 04:45 AM
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); }
05-13-2010 10:47 AM
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
05-17-2010 12:58 AM
#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; }
05-17-2010 11:00 AM
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.
05-18-2010 12:52 AM
Hi Jared,
It works well with VAL_MARKED!!!!
i was bit misconfused with VAL_MARKED and VAL_SELECTED.
thanks a lot for ur solution....