Add Checkbox to Listbox Cells

I need to provide a Checkbox to all cells in a Listbox Column. This Checkbox also needs to ensure that it is the only Checkbox selected in all the rows of the Listbox. The Listbox rows are variable in length.

I am currently using the following code

Listbox1.ColumnType(2) = Listbox1.TypeCheckbox
Listbox1.ColumnAlignment(2) = Listbox1.AlignCenter
      
For count = 1 to x
    Listbox1.AddRow ("","Port " + Str(count)) // Column 0 = blank, Column 1 = Port x, Column 2 = Checkbox
Next count

FYI:I have also used Listbox1.CellType(Listbox1.Lastindex, 2) = Listbox1.TypeCheckbox inside the loop and this yielded the same results

The first thing I notice is that when I click on the cell with the Checkbox it disappears.

  1. How does one keep the Checkbox from disappearing?
  2. Also Listbox1.ColumnType(2) = Listbox1.TypeCheckbox does not center the Header nor the Checkbox’s.
  3. Then once this is resolved I need to make sure that only 1 Checkbox is ever selected.

Thanks in advance for any assistance you can lend

Well, things work fine here, so maybe you have somewhere code which resets the cell to have no checkbox?
Can you show some code?

What happens if you put anything in cell 2? It’s been a while but I think I remember having to have some text (just a space will do) in the cell where the checkbox appears. If there was no text there was no checkbox.

I might be totally wrong but worth a try.

Thansk for the suggestion. I dug in and took a look and I did have some code that enabled edit the ListBox

Me.CellType(row,column)=ListBox.TypeEditable

By checking the column and preventing this on Column 2 all was ok.

I am now trying to figure out how to only have one check box enabled at a time. A Control array or Control set may work but I do not see how to implement in a variable ListBox row length

In ListBox.CellAction, you can just check if your checkbox column was clicked and if so, uncheck all the other checkboxes.

If column = 2 Then For i As Integer = 0 To Me.ListCount-1 If i <> row Then Me.CellCheck(i, column) = False End If Next End If

Paul - sometimes it is that simple

Thanks