PaintHeaderContent Problem

Hi Guys

Can anyone help me with this?

I have a DesktopListBox header that I want a darker background fill colour and a lighter foreground text colour.

PaintHeaderBackground Event:
#If TargetWindows
#Pragma unused column

g.DrawingColor = CL_ListHeaderBackground ← This is a darker teal colour
g.FillRectangle(0, 0, g.Width, g.Height)

Return True

PaintHeaderContent Event:
#If TargetWindows
#Pragma unused column

g.Bold = True
g.DrawingColor = CL_ListHeaderText ← this is White

Return True

The combination of these 2 events gives me a header with a dark teal background but not visible white text.

Any ideas/help would be greatly appreciated.

Cheers, Ken.

Ahem, you aren’t drawing anything in the PaintHeaderContent.


I initialise the listbox on the opening event:

Using Debug

Print(CurrentMethodName + “(” + “)”)

Me.HasHeader = True
Me.ColumnCount = 9
Me.ColumnWidths = “12%,9%,9%,9%,9%,9%,9%,9%”

Me.HeaderAt(0) = “Date”
Me.HeaderAt(1) = “Calls”
Me.HeaderAt(2) = “Connections”
Me.HeaderAt(3) = “SMS”
Me.HeaderAt(4) = “Email”
Me.HeaderAt(5) = “CMA”
Me.HeaderAt(6) = “Appraisal”
Me.HeaderAt(7) = “Form 6”
Me.HeaderAt(8) = “Comments”

Me.ColumnSortTypeAt(0) = DesktopListbox.SortTypes.Sortable
Me.ColumnSortTypeAt(1) = DesktopListbox.SortTypes.NotSortable
Me.ColumnSortTypeAt(2) = DesktopListbox.SortTypes.NotSortable
Me.ColumnSortTypeAt(3) = DesktopListbox.SortTypes.NotSortable
Me.ColumnSortTypeAt(4) = DesktopListbox.SortTypes.NotSortable
Me.ColumnSortTypeAt(5) = DesktopListbox.SortTypes.NotSortable
Me.ColumnSortTypeAt(6) = DesktopListbox.SortTypes.NotSortable
Me.ColumnSortTypeAt(7) = DesktopListbox.SortTypes.NotSortable
Me.ColumnSortTypeAt(8) = DesktopListbox.SortTypes.NotSortable

Me.ColumnAlignmentAt(0) = DesktopListbox.Alignments.Center
Me.ColumnAlignmentAt(1) = DesktopListbox.Alignments.Center
Me.ColumnAlignmentAt(2) = DesktopListbox.Alignments.Center
Me.ColumnAlignmentAt(3) = DesktopListbox.Alignments.Center
Me.ColumnAlignmentAt(4) = DesktopListbox.Alignments.Center
Me.ColumnAlignmentAt(5) = DesktopListbox.Alignments.Center
Me.ColumnAlignmentAt(6) = DesktopListbox.Alignments.Center
Me.ColumnAlignmentAt(7) = DesktopListbox.Alignments.Center
Me.ColumnAlignmentAt(8) = DesktopListbox.Alignments.Center

Me.SortingColumn = 0

You need to draw something here:

PaintHeaderContent has a column parameter. Put your header data into a property and then references that from the PaintHeaderContent.

Var columnHeaderText As String = “TBA”

Select Case column
Case 0
columnHeaderText = “Date”

End Select

g.Bold = True
g.DrawingColor = CL_ListHeaderText

Return True

Like that?
Not sure about the ,0,0) part of the DrawText though?

0,0 is not going to work for painting - you won’t be able to see anything. I’ve used 10, 20 for testing.

Sub Opening() Handles Opening
  const theHeader as String = "bla,blub,blubber"
  HeaderValues = theHeader.Split(",")
End Sub

Function PaintHeaderContent(g As Graphics, column As Integer) Handles PaintHeaderContent as Boolean
  g.DrawString(HeaderValues(column), 10, 20)
  Return True
End Function


Thank you for your patience and expertise.

… now I just have to ‘fiddle’ to get centering on each column.

Cheers, Ken.


Fiddle how? Are your columns resizeable? Do you want to keep the text centred even when a column is resized?

I don’t do anything explicit to make the columns resizable, but I do to make them centered.

I’m currently doing this to get the header text centered in each column header:

Var x As Integer = 10
Var y As Integer = 13

Select Case column
Case 0
x = 25
Case 1
x = 16
Case 2
x = 0
Case 3
x = 15
Case 4
x = 10
Case 5
x = 13
Case 6
x = 3
Case 7
x = 6
Case 8
x = 45
End Select

g.Bold = True
g.DrawingColor = CL_ListHeaderText
g.DrawText(LO_CallsListHeaderTitles(column), x, y)

Return True

More than happy to hear better suggestions. :ok_hand:

A lot simpler to use g.textwidth(mytext) to get the width of the text you want to put out there, and mylistbox.ColumnAttributesAt(i).WidthActual to get the width of column i. From these you can calculate what the x-offset needs to be. And it works for all columns even if they’re resized.

This is why I love this community.

Works like a charm!

Var x As Integer = 10
Var y As Integer = 13
Var t As String = LO_CallsListHeaderTitles(column)
Var w As Integer = g.TextWidth(t)
Var a As Integer = Me.ColumnAttributesAt(column).WidthActual

x = (a - w) / 2
If (Not Debug.DSSAssert(CurrentMethodName, “x”, x, GL_ERR, AS_GREATERTHAN, DENDebug.AssertMessages.QuitWithErrorMessage)) Then Return False

g.Bold = True
g.DrawingColor = CL_ListHeaderText
g.DrawText(t, x, y)

Return True


1 Like