Listbox - ColumnAlignmentOffset

I would like to center a checkbox within a cell of the listbox.
The ColumnAlignment and ColumnAlignmentOffset properties don’t work for a checkbox.
Does anybody know a way to have a checkbox centered within a listbox-cell without going into composing my own graphics.

I cannot fire Xojo right now, but what about (if possible) get the Cell’s CheckBox width and set the Column accordingly ?

If the above does not works:
add a Cell width report (for a Cell with a CheckBox)
run the project,
resize the column who have a CheckBox,
Get its width

Do that for all supported platforms,
And in the Open Event, set the column width using the value for each platform.

I suppose the CheckBox width is different in each platform.

Sorry, no. But before investing too much time in other “Tricks”: Drawing a Rectangle followed by the Text, centered in the Cell and on demand putting a litte Checkmark Picture on top of the Rectangle, should be not to much work. (As long as you have full control over Font, TextSize and so on). :slight_smile:

Unfortunately i do not have a Dev Machine nearby and can’t test it for myself, to offer any Code to you. :frowning:

Just a Quick & Dirty one for Tests or to get started:

In the CellTextPaint Event

[code]Dim strCheckMarkBold As Text = Text.FromUnicodeCodepoint(10004)
Dim dblTextX As Double

dblTextX = g.StringWidth(Me.Cell(row,column))
dblTextX = (g.Width / 2 - dblTextX / 2)

g.DrawRect(dblTextX + 1, 1, g.Height - 2, g.Height - 2)
g.DrawString(Me.Cell(row, column), dblTextX + 20, g.Height-3)

If row MOD 2 = 1 Then

g.DrawString(strCheckMarkBold, dblTextX - 1, g.Height - 5)

End If

Return True[/code]

Same Code, reduced for a CheckBox only Case:

[code]Dim strCheckMarkBold As Text = Text.FromUnicodeCodepoint(10004)

g.DrawRect(g.Width / 2 + 1, 1, g.Height - 2, g.Height - 2)

If row MOD 2 = 1 Then

g.DrawString(strCheckMarkBold, g.Width / 2 - 1, g.Height - 5)

End If

Return True[/code]

BTW: The above Code should work by Copy&Paste, but is written from my mind. There may be errors… :wink:

A last one! You could go for UniCode all the way. So you would not even have to mess with CellTextPaint:

[code]Dim strCheckedBold As Text = Text.FromUnicodeCodepoint(128505)
Dim strCrossedBold As Text = Text.FromUnicodeCodepoint(128503)

Me.ColumnAlignment(0) = ListBox.AlignCenter
Me.AddRow strCheckedBold
Me.AddRow strCrossedBold[/code]

See <> about this issue. Let’s promote it.

“Listbox.ColumnAlignment is ignored when ColumnType is set to Checkbox”
From juni 2012 till now, 2019r2.1 , I gave up with this one. It just gets no attention.
A while ago I had to deal a lot with Listbox controls on desktop. We just lack a good grid. Call it workaround-programming consuming a huge amount of development time to get it acceptable for the enduser.