LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

select all child items in a tree when a parent item is clicked

How can I select all child items in a tree when a parent item is clicked?
0 Kudos
Message 1 of 4
(3,524 Views)
Hi Isn,

There is not anything built in to let you do this, but you'll want to do something like this in the tree's callback function:

int CVICALLBACK treeCallback (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{

    int numChildren;
    int i;

    case EVENT_SELECTION_CHANGE:
           
            if (eventData1)      //if the item is being selected (not deselected)
            {              
                GetTreeItemNumChildren(panelHandle,PANEL_TREE,eventData2,&numChildren);   //get the number of children

                for(i = eventData2; i <= eventData2+ numChildren; i++)      //iterate from the parent's index through all the children's
                {
                     SetActiveTreeItem (panelHandle, PANEL_TREE, i, VAL_ADD_ITEM_TO_SELECTION);    //add them to the selection             
                }
            }
             break;
}

Let me know if you have any questions about this snippet of code.
Kristen
National Instruments
0 Kudos
Message 2 of 4
(3,482 Views)
It depends if you're really talking about selection (highlighting) or checking the items' checkboxes (when "show marks" is on). If you turned on "Show Marks" from the Advanced Tree Options dialog in the control editor dialog (or set ATTR_SHOW_MARKS programmatically), then you can also turn on "Mark Reflect" (or set ATTR_MARK_REFLECT) from the same dialog. This option causes the parent and child items' checkmarks to depend on each other. That is, if you check/uncheck the parent, it will check/uncheck all children, too. If you check/uncheck a child, it may cause the parent to be "partially" checked (indicated by a filled square) if its children are a mix of checked and unchecked items.

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

Here is another way to select all child items....

int CVICALLBACK TreeCB (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_SELECTION_CHANGE:
   {
   int selectionToggleOn = eventData1;
   int parent = eventData2;
   int item;
   
   GetActiveTreeItem(panelHandle, control, &parent);
   for (GetTreeItem(panelHandle, control, VAL_CHILD, parent, VAL_FIRST, VAL_NEXT_PLUS_SELF, 0, &item);
    item>0;
    GetTreeItem(panelHandle, control, VAL_SIBLING, item, item, VAL_NEXT, 0, &item))
    {
    SetTreeItemAttribute (panelHandle, control, item, ATTR_SELECTED, selectionToggleOn);
    }
   }
   break;
  }
 return 0;
}

This will select and unselect all child items whenever the parent item is selected or unselected.

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