Setting indeterminate checkbox in listbox

In a listbox I have a column with checkboxes. Those checkboxes need to have 3 states. When loading data from the database everything works fine:

for currentRow as Integer = 0 to me.RowCount - 1
  dim theIndex as Integer = getRowTagIndex(currentRow)
  if theIndex = -1 then continue
  if SelectionStatus(theIndex) = 1 then
    me.CellCheckBoxStateAt(currentRow, 1) = CheckBox.VisualStates.Checked
  elseif SelectionStatus(theIndex) = 2 then
    me.CellCheckBoxStateAt(currentRow, 1) = CheckBox.VisualStates.Indeterminate
  end if

But setting the CellCheckBoxState in the CellClick event like this does’t work:

'set cell state, checked -> indeterminate, indeterminate -> unchecked, unchecked -> checked
if me.CellCheckBoxStateAt(row, column) = CheckBox.VisualStates.Checked then
  me.CellCheckBoxStateAt(row, column) = CheckBox.VisualStates.Indeterminate
ElseIf me.CellCheckBoxStateAt(row, column) = CheckBox.VisualStates.Indeterminate then
  me.CellCheckBoxStateAt(row, column) = CheckBox.VisualStates.Unchecked
ElseIf me.CellCheckBoxStateAt(row, column) = CheckBox.VisualStates.Unchecked then
  me.CellCheckBoxStateAt(row, column) = CheckBox.VisualStates.Checked
end if

If I have a checked checkbox then clicking on the checkbox removes the checkmark. Clicking on the checkbox again should show an indeterminate checkbox. Instead the checkbox is unchecked.

What am I doing wrong?


causing this CellCheckBoxStateAt =
maybe a cellclick “event”

Could be. But shouldn’t the event fire in this case?

Got it: use CellAction and not CellClick and I don’t check the state of the cell:

dim theNode as AppleListboxRow = GetChildAtRowNumber(row)
if theNode = Nil then Return
dim theIndex as Integer = MailboxPaths.IndexOf(theNode.Tag)

if SelectionStatus(theIndex) = 0 then
  SelectionStatus(theIndex) = 1
  me.CellCheckBoxStateAt(row, 1) = CheckBox.VisualStates.Indeterminate
ElseIf SelectionStatus(theIndex) = 1 then
  SelectionStatus(theIndex) = 2
  me.CellCheckBoxStateAt(row, 1) = CheckBox.VisualStates.Checked
ElseIf SelectionStatus(theIndex) = 2 then
  SelectionStatus(theIndex) = 0
  me.CellCheckBoxStateAt(row, 1) = CheckBox.VisualStates.Unchecked
end if

Have you tried by returning true at the end of the CellClick event? That’s easy to forget and would make the framework handle it like you don’t want.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.