LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I change color of existing labels in listbox.

How do I change color of existing labels in a listbox.
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 1 of 11
(6,645 Views)
I know with this function I can change all labels but I need to change specific label color.
 
SetCtrlAttribute (panelMain, MAIN_LISTBOX, ATTR_TEXT_COLOR, VAL_GREEN);
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 2 of 11
(6,641 Views)
The tree control supports different colored item labels via SetTreeItemAttribute(....ATTR_LABEL_COLOR...), so I'd suggest replacing your listbox with a tree control.  Luckily, you can pass a tree control to all the same functions you call on a listbox, so replacing it shouldn't be difficult.  You will just have to set a few attributes on the tree (for example, to turn off ATTR_SHOW_CONNECTION_LINES and ATTR_SHOW_PLUS_MINUS) to make it look like a listbox.

Hope this helps.

Mert A.
National Instruments
Message 3 of 11
(6,637 Views)

Well, the listbox actually permits the use of escape codes to set some attributes for individual list items or even part of them: this is accomplished by embedding in the string passed to the control some special labels by which you can set text foreground and background color, separate and column the elements and add some vertical line where desired. All this matter is described in the online help for InserListItem command which you should study carefully to see which possibilities are available. Just to have an example, this is the way to have a list item coloured in blue and red:

   sprintf (item, "\033fg%06XThis text is written in blue \033fg%06XAnd this one in red", VAL_BLUE, VAL RED);
   InsertListItem (panelHandle, PANEL_LISTBOX, -1, item, value);

Even after the introduction of the tree control, to display data when I have none or little interaction with the control I prefere using a listbox instead of a tree since that control is significantly faster in displaying data and easier to program.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 11
(6,625 Views)

Thanks Roberto.

Actually I want to change color of an existing label in listbox. I know I can change color when I insert new item.

Also, is there anyway to set label from index? I want to change label from index. I see GetLabelFromIndex function but I don't see SetLabelFromIndex.

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 5 of 11
(6,618 Views)
You can use GetLabelFromIndex, GetValueFromIndex, modifiy the existing label according to your needs and use ReplaceListItem to insert the modified label to the listbox replacing the old one.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 6 of 11
(6,613 Views)
Thanks again Roberto. That will work.
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 7 of 11
(6,607 Views)

Hello,

thanks for this efficient answer.  By any luck, is there a similar procedure for elements in a table?  I tried your example, but it actually prints the numbers after the escape code, instead of changing  the colors...
Many thanks!

0 Kudos
Message 8 of 11
(3,896 Views)

Table cells can be tailored calling SetTableCellAttribute; the color of text can be set with ATTR_TEXT_COLOR attribute. In order to work on a set of cells you can use SetTableCellRangeAttribute.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 11
(3,882 Views)

Many thanks for your fast answer. Unfortunately, I was not precise enough in my question.  I would like to have, in a single cell, different colors of texts and/or background, as it seems to be possible in a listbox...  Thanks again.

0 Kudos
Message 10 of 11
(3,865 Views)