Listbox Highlight

Is there a way to control the highlight colour of the cell you click on?

cellbackgroundpaint

I use cellbackgroundpaint to paint every second cell blue/white/blue… before populating the listbox.
When I click on a cell it highlights the cell in green.
I can’t see that I am setting it to green anywhere, what controls that?

do you return ‘true’?

1 Like

No because I want the cell clicked to be highlighted just not in green

Can you share a screen capture and the code you use?

I’ve never seen a green highlight. A few days ago I changed CellBackgroundPaint and CellTextPaint to change the look of a listbox.
When I click the first row cells - no highlight.
When I click the first column cells (except first row) - highlight the row
When I click second row, second column and beyond, only the cell clicked is highlighted.

Could green be your operating system selection colour?

From memory, you need to return true in the cell background paint event to avoid the default background painting.

Paint the row in the highlighted color if the row is selected.

Then return true

Taken from the LR: http://documentation.xojo.com/index.php/ListBox.CellBackgroundPaint

[quote]Returns a Boolean. True means the user has handled the background paint and no other processing is to be done with the background. In this case the user is responsible for all highlighting. False means the user wants the default background; this will overwrite your drawing on the row that needs to be highlighted as the row or column will be highlighted as appropriate (according to the platform and the hierarchical style).

AND

Before CellBackgroundPaint fires, some drawing may have taken place. It isn’t safe to assume that the background of the cell is white or that the selection hasn’t already been drawn. If you need the background to be clear, you need to clear the background yourself and then return True.[/quote]

But please read as:

:slight_smile:

Thanks Jeff and Sascha :slight_smile:

If you want to work with sympathetic colour schemes to the system colours eg HighlightColor, is there a way to get its RGB values?

The Language Reference is your friend: http://documentation.xojo.com/index.php/HighlightColor and http://developer.xojo.com/color :wink:

Can’t test it currently, but HighlightColor is a Color Object and you should be able to access it’s RGB Properties.

Thanks Sascha I was just in that spot and I think I am on the right track with the following…

Dim c As Color
c = RGB(HighlightColor.Red, HighlightColor.Green, HighlightColor.Blue)

OR

Dim c As Color
c = HSV(HighlightColor.Hue, HighlightColor.Saturation, HighlightColor.Value)

… or simply

Dim c as Color = HighlightColor

[quote=403350:@Ulrich Bogun]… or simply

Dim c as Color = HighlightColor

it is not the same color as the finder highlight color for example, of xojo listboxes highlightcolor.
how can we get the system highlightcolor (which seems darker than the xojo highlightcolor function that seems the system texthighlightcolor ?

Have you tried https://xojo.gitbook.io/add-ons/cstruecolors?

none of them seems to be the one.
highlightcolor is this color :

the one I search is :

I already got it with a color picker, it’s &c0850CF
but I would like if I could get it with some system method ?

Did you compare it to the pictures on the site or did you run the demo on your Mac?
Under Mojave, there are an AccentColor and a SelectionColor, both customisable by the user and often modified with AddSystemColorEffect. Sometimes Apple uses a custom Color in their apps that has no system resemblance.

the color I want is in Xojo built-in listbox !
I want to select my own cells in a subclass of listbox, so my search for the same selection color as the listbox.

They may have used a declare. Maybe a feature request to expose the color to us?