LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Beginner - Tree and Checkbox

There is a tree in the panel with a lot of elements. I set on the option to the tree has one checkbox for each element.

    int val = 0;
    GetCtrlVal(Handle, TREE, &val);
    SetCtrlAttribute(Handle, TREE, ATTR_SHOW_MARKS, val);

The user can check so many box as he wants, but when he clicks a command button, I have to do some tasks.

How can I know which boxes are checked? For each one element that was checked, I have to display a message , so I implement a while loop to do. But in order to display the message, I have to get the item label. How can I do it?

Thank you in advance.

0 Kudos
Message 1 of 3
(4,036 Views)

Hello Oliveira,

I am a bit confused about your code:

    int val = 0;
    GetCtrlVal(Handle, TREE, &val);
    SetCtrlAttribute(Handle, TREE, ATTR_SHOW_MARKS, val);

If you want to show marks on the tree control. You should use this line of code:

    SetCtrlAttribute(Handle, TREE, ATTR_SHOW_MARKS, 1);

To answer your question: special tree functions are located in the User Interface Library -> Controls/Graphs/Strip Charts -> List/Tree(Lable/Value) Controls. From this library, use the IsListItemChecked (Handle, TREE, index, &checked) function. If the item with the given index is checked, the variable "checked" will be 1. If not, "checked" is 0. To get the item's label, use the function GetLabelFromIndex (Handle, TREE, index, label), where the variable label is a string (array of chars):


int index ,num_indices;
int checked;
char label[100];
char message[100];

GetNumListItems (Handle, TREE, &num_indices);
for (index = 0; index < num_indices; index++){
     IsListItemChecked (Handle, TREE, index, &checked);
     if (checked){
        GetLabelFromIndex (Handle, TREE, index, label);
        Fmt (message, "List item %s is checked.", label);
        MessagePopup ("Tree", message);
     }
}
 
Hope this helps...

Message 2 of 3
(4,021 Views)

This will do the trick:

   int item;
   char buf[100];
   /* this gets the first item that is marked */
   GetTreeItem(panel, PANEL_TREE, VAL_ALL, 0, VAL_FIRST, VAL_NEXT_PLUS_SELF,
    VAL_MARKED, &item);
   while (item >= 0)
    {
    GetTreeItemAttribute(panel, PANEL_TREE, item, ATTR_LABEL_TEXT, buf);
    printf("%s\n", buf);
    /* this gets the next item that is marked */
    GetTreeItem(panel, PANEL_TREE, VAL_ALL, item, item, VAL_NEXT, VAL_MARKED, &item);
    }

Message 3 of 3
(3,993 Views)