LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can the color of selected items in a Tree Control be changed?

I have looked and looked and I am either blind or the attributes I need don't exist.

I would like to change the text and background colors used to highlight a selected item in a tree control but I can't seem to determine if this is possible. If it is, what attributes do I change?

Any help would be greatly appreciated.
Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 1 of 4
(4,105 Views)
Martin,

Try implementing this on a LEFT_CLICK event:


/*Get the current index of the tree control*/
GetCtrlIndex (panel, PANEL_MYTREE, &index);

/*Set the text of the currently clicked item to blue*/
SetTreeItemAttribute (panel, PANEL, index, ATTR_LABEL_COLOR, VAL_BLUE);

/*Set the background of the currently clicked item to green*/
SetTreeCellAttribute (panel, PANEL, index, 0, ATTR_LABEL_BGCOLOR,VAL_GREEN);
0 Kudos
Message 2 of 4
(4,098 Views)
Hmm... well, not exactly what I was hoping for. Seems like a rather hokey way to go to change the highlight color. An attribute setting for the highlight text color and background color were what I would really like so I can set it once and be done with it. Using this method, I have to not only change the color of the selected item but change the color of the previously selected item back to the default when the selection is changed.

If the highlight colors were tied to the system colors, this would not be an issue. The problem is that when the tree control is using its default colors (black text on white background) the highlight is a thin black outline. This is a bit too subtle in my opinion.

Note to NI for future enhancements... Please, please, please make attributes available for setting the highlighted text and background colors.
Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 3 of 4
(4,092 Views)
The tree's highlight colors are tied to the system colors. Drop a new tree control in the UI editor, add a couple of items, and select an item or two; the highlight colors should be the same as they are in the Windows Explorer tree.

From your comment about the highlight being a thin black outline, I'm guessing that you have the tree's ATTR_SELECTION_MODE to VAL_SELECTION_NONE. In this mode, no items can be selected; there is only the active item, which is denoted by the thin black dotted outline. If you change the ATTR_SELECTION_MODE to VAL_SELECTION_SINGLE, there will always be exactly one selected item (whose colors will be the same as the system colors), and it is always the same item as the active item. If you change the ATTR_SELECTION_MODE to VAL_SELECTION_MULTIPLE, you'll be able to select no items or multiple items.

The thin black dotted outline indicates the active item, and the tree always has an active item. The selection mode determines which items, if any, are selected (highlighted).

- jared
0 Kudos
Message 4 of 4
(4,085 Views)