Push buttons in DesktopListBox?

For Windows, I’d like to place a push button in a cell for a specific row (as I do in Cocoa):

Most of the postings that discuss this are several years old, prior to the new API, and it sounds painful to do. Is that still the case?

I could redesign the UI to use a checkbox cell and a button OUTSIDE of the table, or just have the user select the row and press a button outside the table, but since only one row can be operated on at a time, placing the control inside the cell seems the best choice.

Placing an arbitrary control in a Table/ListBox is something I do all the time in more sophisticated applications – sure would be nice if Xojo supported that…

1 Like

not found a button cell type.
there is a DesktopListBox.CellPressed event.
never understood why a cell can not be any control in this OOP world.

@MarkusR – exactly – what makes a checkbox different than a push button? I have popup menus, checkboxes, push buttons, editable text fields, disclosure triangles, color swatch control etc all over my list box / Tables over on MacOS / IOS.

You can do this with a little “Quick’n Dirty” workaround. Here’s a Proof of Concept sample project.

1 Like

@Martin_T – That’s a very nice example of a viable workaround, Martin.

I don’t suppose there’s a way to have Xojo go into a mouse-down loop and track if the mouse is in the cell, and only draw the button highlighted if the mouse is still in the cell bounds? I think most users would expect a button-like shape to have basic control/button behavior.

Yes there is… If you return True in MouseDown you then get MouseDrag events where you can do that.


@KarenA – how do you get the cell’s coordinates? I see how to get the row and column from mouse coordinates, but MouseDown is an event of DesktopUIControl, not of a cell (right?). You would need the cell’s coordinates, local to the ListBox in order to do a meaningful comparison (and take into account scrolling).

I don’t know the current names but in API 1:

you can use Listbox.RowFromXY and Listbox.Column From XY to get the cell coordinates in mousedown

then in drag to see what cell the mouse is over you can do the same thing…

If you want to be more specificities than just which cell (such as if you are within the drawn button area in a cell, you can use a combination of:

ListBox.ScrollPosition , ListBox.ScrollPositionX , and CellWidthActual to get the X,Y values for the start of the cell.

Not as hard as it sounds. If I can do it I’m sure you can with a little trial and error!


Thanks Martin
I have your example with desktop canvas and desktop oval
expanded and works very well.
Finally, when you activate a line, the blue background is just a background.
So far, my drawings or images have been overdrawn in PaintcellBackgroud in blue

You should use PaintCellText-Event for drawings within a cell not a Canvas/Oval/Rectangle control.

Hello Martin,
I was just using PaintCellText event for my color control the whole time. The idea of putting my pictures there with g.drawpicture didn’t occur to me either.
Thank you