Can we control the selected row color for non-Focused listboxes

I’m have surprising success over this holiday break (amazing what you can do without business distractions) with my ListBox efforts.

However, I’ve tried a number of CellBackgroundPaint options to try and prevent the light gray that appears when the listbiox has a row selected and then loses focus. I’ve tried setting a flag in the LostFocus event to control the Paint, but it doesn’t seem to have any effect since it doesn’t appear that the CellBackgroundPaint event isn’t called when the ListBox loses focus. I even tried raising the CellBackgroundPaint even in the LostFocus, but that was an interesting bit of result.

Is it possible to stop what appears to be an XOR of the BG color? If so, how?

[quote=366305:@Tim Jones]I’m have surprising success over this holiday break (amazing what you can do without business distractions) with my ListBox efforts.

However, I’ve tried a number of CellBackgroundPaint options to try and prevent the light gray that appears when the listbiox has a row selected and then loses focus. I’ve tried setting a flag in the LostFocus event to control the Paint, but it doesn’t seem to have any effect since it doesn’t appear that the CellBackgroundPaint event isn’t called when the ListBox loses focus. [/quote]

I bet you forgot to return true in CellBackgroundPaint!

In CellBackround paint just do

If me.Selected(row) Then G.ForeColor = mySelectionColor g.FillRect 0,0, g.Width, g.Height Return True End if

You should might also need to set the g.Forecolor in CellTextPaint for selected rows…

That way a selected row will always look the same no matter the state of the listbox or the window

The only trick is getting the right selection background and textColors if you don’t want to use your own selection color… and for that (at least on a Mac) you need to use declares

The LB selected colors (enabled and disabled) should be computed properties on the Listbox IMO!! When you are doing custom listbox stuff I found I often needed them if I wanted to have a consistent looking UI!

  • karen

Thanks, @Karen Atkocius - returning True was missing in that one specific CellBackgroundPaint event.

If I were a dog, I’d have been chasing my tail :S

Sorry to revive this thread - but having a similar problems.
In contrast the the above posts, i do return true in both events and set colours etc, but i can’t seem to affect the ugly grey row fill colour when listbox loses focus…

any other suggestions? (2019r3)

[quote=493169:@Stam Kapetanakis]Sorry to revive this thread - but having a similar problems.
In contrast the the above posts, i do return true in both events and set colours etc, but i can’t seem to affect the ugly grey row fill colour when listbox loses focus…

any other suggestions? (2019r3)[/quote]

Post the code you are using and what event it is in and we can help you.

-Karen

Just bear in mind, that the ugly gray color serves a purpose, in that it shows which row is selected, but that listbox (or window) does not have focus.

As long as you understand the reason as to why it does this, before you alter the colors.

btw: I am not saying that you shouldn’t, just that it does this for usability purposes.

To clarify:
the code (and feel free to criticise this!) is below. hoveredRow is a property of the subclassed listbox that gets set to the RowByXY on mouseEnter. The colours are predefined constants:

CellBackgrounPaint

[code]If row = Me.SelectedRowIndex Then
g.DrawingColor = kBackgroundHiliteLight
Elseif row = Me.hoveredRow Then
g.DrawingColor = kBackgroundHoverLight
Elseif row Mod 2 <> 0 Then
g.DrawingColor = kBackgroundAlternateLighter1
Else
g.DrawingColor = kBackgroundOffWhite
End If

g.FillRectangle(0,0,g.Width,g.Height)
Return True[/code]

CellTextPaint

g.DrawingColor = kTextDark If Me.SelectedRowIndex = row Then g.DrawingColor = kTextLight Return True

Apart from the aesthetics of colour - which are awful when the listbox looses focus in my layout - the issue is that this code sets the text colour to light theme because the selected row is dark; but when it looses focus it becomes light, so you end up with light text on a light background :-/

Ideally i would not want the listbox to give the appearance of loosing focus at all… or at least select a different ‘inactive’ colour to maintain consistent colour scheme…

Does MouseEnter fire when teh listbox does not have the focus?

In any case in MouseEnter try Assigning HoverRow and then if HoverRow not selected then invalidate the HoverRow

-Karen

@Karen Atkocius Thanks - do you mean setting the HoveredRow to -1 on mouseExit and invalidating?
This would probably work, inasmuch as no row would be selected - workable but not ideal.

I take it there is no way to change the out-of-focus grey then?

Well you could un select the selected row…

[quote=493242:@Stam Kapetanakis]I take it there is no way to change the out-of-focus grey then?[/quote]In the current listbox implementation it seems that the selected row highlight is always that gray when the listbox does not have the focus. So the options are either to put up with it or to unselect the row (set listindex to -1) and not have it highlighted.

If all you want is a way to indicate which row WAS selected but don’t want that gray highlight, an alternative might be to set the cells to bold for the row when the listbox loses the focus and restore them to normal, and set the previously saved listindex, when the listbox gets the focus again.