Configure a complex Cell in ListBox

Hello,

Is there a way to create a complex cell in a listbox like in the macOS Mail App: Each cell contain a title, a date, a flag, some text…

You mean:

Goodies 2022-04-04 :fr: Famous

?

Une copie d’écran serait plus explicite.

Sure, you need to use the DesktopListbox.PaintCellText-Event.

Je ne comprends pas mieux.

Pourquoi vouloir utiliser un ListBox si tu veux copier ton Airbnb ? Prends un Canvas…

This shows you how to use the DesktopListbox events PaintCellText and PaintCellBackground. Since I’m accessing a macOS system color (selection color), the code in PaintCellBackground is macOS-only.

PaintCellText

If Row = -1 Then Return False

g.Bold = True
x = 23
y = 10 + g.FontAscent
g.DrawText("Airbnb", x, y)
g.Bold = False

If row <> Me.SelectedRowIndex Then g.DrawingColor = Color.Gray
g.DrawText("hier", g.Width - x - g.TextWidth("hier"), y)

If row <> Me.SelectedRowIndex Then g.DrawingColor = Color.TextColor
y = 32 + g.FontAscent
g.DrawText("Découvrez le commentaire que Willeke a rédigé", x, y)

If row = 1 Then
  
  Static sFlag As String = Encodings.UTF8.Chr(1049290) ' macOS-only (SF Symbol)
  
  If row <> Me.SelectedRowIndex Then g.DrawingColor = &c33669800
  g.DrawText(sFlag, g.Width - x - g.TextWidth(sFlag), y)
  
End If

If row <> Me.SelectedRowIndex Then g.DrawingColor = Color.Gray
y = 55 + g.FontAscent
g.DrawText("Découvrez comment vous avez été évalué pour votre voyage Voici le commentaire de Willeke Willeke Sebastien communiceert netjes en...", x, y, g.Width - (x * 2), False)

Return True


PaintCellBackground

If row <> Me.SelectedRowIndex Then Return False

g.ClearRectangle(0, 0, g.Width, g.Height)

g.DrawingColor = Color.White
g.FillRectangle(0, 0, g.Width, g.Height)

Const x As Integer = 10

Static oSelectionColor As New ColorGroup("controlAccentColor") ' macOS-only

g.DrawingColor = oSelectionColor
g.FillRoundRectangle(x, 0, g.Width - (x * 2), g.Height, 8, 8)

Return True

2 Likes