Microsoft ListView text color

I'm using a Microsoft ListView control in my program and want to change the color of the selected item in the list. Does anyone know how to do that? I tried using :ForeColor but any integer I assign to it fails to work.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
CyrixInstead's picture

Microsoft ListView text color

The value you assign to the ForeColor needs to be a valid 3 byte integer. The easy way to turn any colour into a 3 byte integer is to 'bitshift' the RGB value of the colour.

The valid range for a normal RGB colour is 0 (black) to 16,777,215 (white). Get the RGB value of the colour you require |R|G|B| i.e. |72|228|36| = light green (the free image editor Paint.Net will give you the rgb colour from a colour wheel).

To bitshift the colour into a valid integer you multiply each octet by the range of the previous octet to "shift" it to the left. For example with the light green mentioned above:

 |72|    228    |      36      |
      *256 (2^8)  *65536 (2^16)        which gives
 |72|   58368   |    2359296   |

You then just add the 3 integers together to give the integer value of the colour.

Here are some examples:

Pale Blue   = 16764875 (203,207,255)
Pale Yellow = 11205630 (254,251,170)
Pale Green  = 13237940 (180,254,201)
Pale Red    = 12303359 (255,187,187)

White       = 16777215 (255,255,255)
Black       = 0        (0,0,0).

The easiest example to show is white:

R  255         =      255
G  255 * 256   =    65280
B  255 * 65536 = 16711680 +
                 --------
                 16777215

I hope that helps!

~Cyrix


Text Color...

Did you tried with ":BGCOLOR" I have used it for browsers before and have worked find.

def var vBackgroundColor as int no-undo.
vBackgroundColor = 11.

:BGCOLOR IN BROWSE br-Browse = vBackgroundColor.

Or directly

:BGCOLOR IN BROWSE br-Browse = 11.


Doesnt Work

I tried that but it doesn't work. I'm using this against a ListView control though, not a browse control...


Use Version 6 Control

There are two versions of the Microsoft ListView control, Version 5
and Version 6. Version 5 does not support setting the foreground
color of an individual row. Version 6 does support this.

If u Remove the control from the window (be sure to save any code you have
attached to events for this control) then add a new instance of the
ListView control and ensure that you select Version 6 of the control
instead of Version 5.


Version 6

Hi,
I do use version 6. I am not sure how to set the color of the text within that version of that control. Nothing I try works. Do you have an example?