CheckBox in Cell of DesktopListBox is editable

A checkbox created in a cell of DesktopListbox can be changed. The following example program illustrates the problem:

ListBox1.AddRow
ListBox1.CellTextAt(0,0) = "Column 0"

ListBox1.CellTypeAt(0,1) = DesktopListbox.CellTypes.Checkbox
ListBox1.CellCheckBoxStateAt(0,1) = DesktopCheckBox.VisualStates.Checked

This piece of code is in the Pressed event of a DesktopButton. The text in cell (0,0) is not editable. The state of the CheckBox (cell (0,1) can be changed. How to avoid this?

In the action event try something like this:

listbox.cellcheckboxstate(x,y) = not listbox.cellcheckboxstate(x,y)

This undos the cellclick.

That’s the whole point. Why would you put a checkbox in a listbox if you didn’t want it to be clickable? If you don’t want it clickable, draw an icon into the cell.

It was late and I may thinking wrong, but I had the same question yesterday/this night.
In that case, I add ā€œāˆšā€ or nothing or…

The ListBox shows a list of members. One column in the list indicates the payment status (paid = checked/unpaid = unchecked. it doesn’t make sense to be able to change the status of a checkbox cell in the ListBox.

Emile, yes of course I can look for another solution to show the status (e.g. True/False, 1/0, a green/red image…). There are so many solutions to solve this problem. My intention was to bring this issue to attention.I think this is still a mistake.

1 Like

Thank you, Beatrix this solves the problem. However, this seems like a bug in Xojo!

Can’t you make it read-only?

I don’t know any method or property to set a CheckBox read-only in a column of a ListBox.

No. You are misusing the checkbox.

1 Like

I think it’s a valid use case: checkbox as read-only display element. Drawing it into the cell would be elegant, but Beatrix’ workaround seems fine and simple.

I agree with the other Tim. An enabled Checkbox indicates to the user it’s an input control. That’s why in Lifeboat, the ā€œIn Useā€ column is a UTF-8 checkmark. I think this communicates the boolean state while also being read only in a clear way.

Anyone interested in taking a similar approach, the char code is:

Encodings.UTF8.Chr(&h2713)
7 Likes

Tim, I don’t agree with your remark. Why do I misuse the CheckBox?

  1. A CheckBox can be used to input/display two-state values. In my case: ā€œPaidā€ and ā€œUnpaidā€;
  2. The Normal/Default CellType of a DesktopListBox is not editable. There is no remark in the documentation that a CheckBox cell changes the Cell type to ā€˜Editable’. Only TextField and TextArea types are defined ā€˜Editable’.
  3. A traditional DesktopCheckBox control can be ā€˜Enabled’ Or ā€˜Disabled’. Why is this not possible for a CheckBox cell in a ListBox?

So, for me this problem is either a minor bug or is a lack in the documentation where a CheckBox cell must be documented as editable.

A checkbox is specifically used to input Boolean / two-state values. When it is enabled the control indicates to the user they can change the value. The Checkbox isn’t clearly read-only until disabled.

Unfortunately, DesktopListbox cannot disable the Checkbox column type so you will need to file a feature request if you wish for the ability.

I would suggest displaying a text checkmark the way I do until you’re able to show read-only checkboxes. The UTF-8 checkmark solution also has the benefit of being cross platform with no extra work :smiley:

Yep, definitely more elegant.

I agree Tim, there are many solutions to solve this problem: I can use True/False, OK/NOK, two different images, two colors (e.g. green is paid, red is unpaid…), etc. This was the first time I tried to use a CheckBox in a ListBox and I was very surprised that this CheckBox cell was editable. From now on I will use the simple UTF-8 checkmark.

@Beatrix_Willius The NOT operator cannot be used in this case (A CheckBox can have 3 states). This is the code you have to use in the CellAction event:

If CellCheckBoxStateAt(row, column) = DesktopCheckBox.VisualStates.Checked Then
  CellCheckBoxStateAt(row,column) = DesktopCheckBox.VisualStates.UnChecked
Else
  CellCheckBoxStateAt(row,column) = DesktopCheckBox.VisualStates.Checked
End If```

If you actually want to allow the user to choose between the three states, CellCheckBoxStateAt is indeed the correct method.
Otherwise, with only two states allowed, you’d better use CellCheckBoxValueAt instead, which simplifies your code as you can use the ā€œnotā€ operator.

1 Like

Thank you Arnaud for adding this important comment!