Replacing a PopupMenu with a ListBox

I actually have a PopupMenu to choose the default template in a Window.

But that template is an image with different background color(s), and I have to modify this part of the project, so I take the opportunity to slicy modify my project.

S, I moved the PopupMenu out of the window and set a ListBox at its place.

Some small adjustments and simple additions were enough to display my (resized to fit in a ListBox Row) images.

All is nice and “working”, but the ListBox Row is “Selected” and this selection rectange hides the image.

I draw the image in the ListBox.CellBackgroundPaint Event.

What can I do now ?

PS: the ListBox keep its size during the process.

If all you want to do is “unselect” the row, simply set the
ListBox.SelectedRowIndex = -1


The ListBox is hilighted while pressing the arrow key to change Row (Image and Text are hilighted).

There is only one visible Row.

I added Return True and now I can see the icon (the color of the icon) but with the selected Color that are above the Icon and the Text, the selection of the Colored Icon is a bit difficult.

This is a Template Icon and the only difference between all of the templates is/are the color (sometimes one color, sometimes two colors).
Th idea is to let the user to choose based on color (it was based on my name for the color…) with a little help (my color name)


Here’s what it looks like. Standard colors (not Dark Mode).

Xojo / Big Sur.

If you want to remove the highlight, you can draw a white rectangle in the CellBackgroundPaint event (don’t forget to return true).
Then, you’ll also have to make your text black, as white on white will be unreadable; draw the cell in the CellTextPaint event, turning the colour to black (and returning true).

Thank you fr your answer.

Actually, I already draw the icon in CellBackgroundPaint, and I also already used Return True.

Oh, and my text is Black (this, I know, does not looks like that in the screen shot). The automatic hilight turns it to white, not me. The ListBox draw the Text, not me.
I have the icon in one column and the text in the other column.

Are you meaning you also tried my tip?

Yes, I know. As soon as you highlight a row in a listbox and the highlight colour is “dark”, the OS (or framework, whatever) draws its text as white. That’s why I suggest you to draw your text manually as black in the CellTextPaint event.

you have darkmode enabled and you expect a other color?
it looks like windows 10 hi light color.

this should draw the selected backbround in own colors

Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) Handles CellBackgroundPaint as Boolean
  If column = 0 Then
    If Me.Selected(row) Then
      g.DrawingColor = Color.Red
      g.DrawingColor = Color.White
    End If
    g.DrawingColor = Color.Green
    Return True
  End If
End Function

No. It’s a two columns ListBox, the result will be surprising (the text is selected while the user choose a colored folder icon).

You want the text to be not selected while the user chooses a coloured folder icon, then? No text at all?
Please explain.

No. I just say the line is selected and what’s in the line (Row). If I remove the “Focus” in half of the Row…