Select a single cell

Hello Group.
Another problem.
I have a table made using a ListBox. When I select a cell, the entire row is selected, the entire row is highlighted.
Is there any way to highlight only the selected cell?

Do the highlighting yourself.

Ok I understand that the cell can be colored in the PaintCellBackground property (g…r…c …)
if row = 2 and column = 3 then
g.ForeColor = & cFF0000
g.FillRect (0.0, g.width, g.height)
end if

But how do I replace the 2 and 3 with the values of the clicked cell? How do I pass these parameters?

They are the parameters for that event handler. Just remove the if/end if.

with the IF condition I select only a cell and colors it red. If I remove the condition it colors all the cells in red. How do I tell it to color only one cell, for example, the one containing the number 16 or the one with BOLD = True.? I DO NOT UNDERSTAND.

You need to store the row & column indexes in properties when the cell is clicked.
In the paint event you would then test the row & column parameters against those properties to see if you should paint to indicate the selection.

OK. You should subclass your listbox and add two properties to it: clickedrow and clickedcolumn, both integers. In the CellPressed event you save the row/column to these properties. Then in CellBackgroundPaint you compare the row/col that this handler gets, with the saved ones, and paint red if they match, white otherwise.

You have an exemple of that in the Xojo Example folder
Example Projects/Desktop/Controls/ListBox/IconGrid

You can easily copy the code and just change the color/rounded border

1 Like

Thanks for the suggestion, I checked the listing, in fact, I hadn’t thought of a “global” variable to store the cell data. Thanks, so I was able to highlight the clicked cell.
Thanks again.