I have a few multiselect listboxes, filled with data, on a window that I use to filter another list.
What happens is that if I make selections from listbox 1 then move to lisbox 2 listbox, 1 looses focus as it should but the highlighting of the selection changes from selected, blue background with white text, to dark grey background with black text. Is there a way to keep the items looking selected even though the listbox looses focus?
As you see, they are selected.
All you have to do is to set the Focus to ListBox1 at the end of the Row Drag to get your “Selected Rows Dark (green ?).
You can override the system-default color by handing the PaintCellBackground event.
Event PaintCellBackground(g As Graphics, Row As Integer, Column As Integer) As Boolean
If Me.RowSelectedAt(row) Then
g.DrawingColor = &cFF00FF00 ' set the color you want to use
g.FillRectangle(0, 0, g.Width, g.Height) ' fill with the color
Return True ' tell the system you handled painting yourself
End If
End Function
Works very well thank you. The only remaining thing is that the text changes from white to black. Not sure if anything can be done about that.
Thank you, but I want all of the boxes that have selections to remain at the same focus-selected color.
For text, see the PaintCellText event, which works similarly to PaintCellBackground:
Event PaintCellText(g As Graphics, Row As Integer, Column As Integer, x As Integer, y As Integer) As Boolean)
If Me.RowSelectedAt(row) Then
g.DrawingColor = &cFFFF0000
g.DrawText(Me.CellTextAt(row, column), x, y)
Return True
End If
End Function
How your users know where the focus is ?
As soon as one or many selections in any or all of the 3 filter listboxes are made, I fire my filter method from the SelectionChanged event, and I filter the big list. I want to be able to refer to what filter criteria I have set.
My problem is, when I set it to white, I can’t see the text when nothing is selected, since it has a white background. I see no way to change it dynamically.
Your code should only paint white if the row is selected.
You may need to update your code.
If you need help, post the code you are using in PaintCellText
It does indeed work. My mistake. Thanks everyone for helping!