Centering Checkbox Cell in Listbox

I though (probably incorrectly) I could center a Checkbox in a Lisbox by setting the alignment of the Column or Cell to center. I’ve tried:

Dim cCnt As Integer Me.ColumnCount = 3 Me.AddRow("C1", "", "C3") Me.CellType(0, 1) = Listbox.TypeCheckbox for cCnt = 0 to (Me.ColumnCount - 1) Me.ColumnAlignment(cCnt) = Listbox.AlignCenter next cCnt

for cCnt = 0 to (Me.ColumnCount - 1) Me.CellAlignment(0, cCnt) = Listbox.AlignCenter next cCnt

Dim tWidth As Integer for cCnt = 0 to (Me.ColumnCount - 1) tWidth = Me.Column(cCnt).WidthActual Me.CellAlignmentOffset(0, cCnt) = (tWidth/2) next cCnt
None do what I’m looking for. So I’m pretty convinced I can’t align the checkbox with the standard methods. Do I need to create my own checkbox (pictures) with two states and paint it in the CellBackgroundPaint? Could I perhaps instantiate the checkbox as an object in code and insert it into the cell as an object? Any pointers or examples to look at?

This is a longstanding bug. You can add this case to your list of top cases in feedback:

In a listbox a cell of TypeCheckbox cannot be centered.


// AlignCenter has no effect!
Me.Listbox1.ColumnAlignment(3) = Listbox.AlignCenter

Yes, this is exactly what I’m seeing. If I were to create my own checkbox (I’m picturing 2 images, one for checked and one for unchecked); how can I embed them into the cell (similar to the little folder and star icons on the left hand of the table on the previous post)?

One can use the ListBox.CellBackgroundPaint event handler in combination with MouseDown or CellClick or CellAction, whatever suits best one’s case. Like this one could also construct a self-made checkbox inside of a listbox cell.

If you store your value in the celltag (this case the checkbox is in column 1) you can use this in the CellBackgroundPaint event

My graphics are 12 x 12 pixel png

[code] if me.ListCount > 0 and row < me.ListCount then

if column = 1 then
  #IF TargetWin32 then
    if me.CellTag(row,column).BooleanValue = True then
      g.DrawPicture(ChkSmallCheckedWin,g.Width/2 + 4, 4)
      g.DrawPicture(ChkSmallWin,g.Width/2 + 4, 4)
    end if
  #elseif TargetMacOS then
    if me.CellTag(row,column).BooleanValue = True then
      g.DrawPicture(ChkSmallChecked,g.Width/2 + 4, 4)
      g.DrawPicture(ChkSmall,g.Width/2 + 4, 4)
    end if
end if

end if [/code]

I started playing with this last night (g.drawpicture) with some decent results… Will add the celltag use. Many thanks.

I’m using the tips from this thread and from with very good results.

Thanks again.