Nicer Listbox for OSX, based on NSTableView (MBS)

For those who use the MBS plugins or are considering them:

I’ve written a set of wrapper classes to make the NSTableView, which is Apple’s native listbox implementation, compatible to use as a replacement for the Listbox (=TableView) class.

The advantage of using Apple’s native TableView over Xojo’s own Listbox is that it looks better (i.e. it conforms to OSX’s other native controls’ appearance) and also does a few things better, especially in regards to resizing multi-column lists, or to handling multi-selection lists.

Not everything can be emulated, so for now it’s only working for “flat” (i.e. non-hierarchical) lists, and there’s no custom CellPaint handlers (though, in many cases, where you only need the custom paint events to add color to your cells, this can be solved with a new Style property now). There’s also no images nor checkboxes, yet.

To try it out, download the most recent beta from

If you don’t want to load all plugins, here’s a list that you will probably need (or the Xojo plugins equivalent):

[quote]MBS Real Studio Cocoa Plugin.rbx
MBS Real Studio CocoaBase Plugin.rbx
MBS Real Studio CocoaControls Plugin.rbx
MBS Real Studio Leopard Plugin.rbx
MBS Real Studio MacOSX Plugin.rbx
MBS Real Studio MacOSXCF Plugin.rbx
MBS Real Studio MacOSXCG Plugin.rbx
MBS Real Studio Main Plugin.rbx
MBS Real Studio Util Plugin.rbx[/quote]

Look inside Examples / for Cocoa Controls. Run the “ListBox TableView.rbp”. It’ll show two listboxes: The upper one is based on my “ListBoxTV” class, the other on Xojo’s original class. You can see how they behave. You may also note a few differences.
See also the Notes section, explaining a few details.

I am working with Christian to enable more features, such as hierarchical lists.

But first, I like to have some feedback from you. If you’ve tried it out, let me know if you find it useful for your own use, yet, or why you don’t, i.e. what missing. I can’t make every standard Listbox feature work, and I primarily implement those that I need myself. If you want more, communicate it, and I’ll see what can be done.


Thanks for creating this example.

Thanks for making it possible, Christian :slight_smile: (I could have done it all with a dylib or with declares, but that’d be quite a lot of work, to cover all the needed classes with declares etc.)

An updated version is available (included with 17.1pr4 plugins)

The “ListboxTV” control is now quite well useable, at least for flat (non-hierarchical) lists. Download the plugins and give it a run.

There are also a few more demos now using the just-added “NSOutlineView” control, for hierarchical lists. I haven’t done a ListBox wrapper for that, yet, but there are demos showing how to use it with its original (native) functions and events.

Has anyone tried this out, yet? There are 6 demos inside 17.1’s /Examples/Cocoa Controls/Listbox and TableView Demos/ now, showing several ways to use the native NSTableView and NSOutlineView controls.

Thank you Thomas for making this happen !!
One thing is still needed. Custom cells. If this could be done, it would be a fantastic replacement for the dreadful old Xojo listbox.
Now it is only useable for spreadsheet-like stuff.

What do you mean by custom cells? The ListBoxTV attempts to only emulate the Xojo ListBox. If you want Custom NSViews or a PopupCell in the list, just extent this yourself. I don’t want to have to start writing documentation for new things that are unknown to ListBox users :slight_smile:

I could, however, add the necessary events so that you can add customization in your own subclass. Or you do that, and send me back your changes.

Well, see it as adding the Cellpaint event :slight_smile:
So it would be great if we can add images, text and even controls into the NSTableView cells.

Well, an idea could be to have a flag to enable CellPaint for a column.
If that’s enabled, the control could keep a picture or each cell in that column.
Call paint event with picture graphics object to update it as needed.
And use a custom nscell to draw it in the cell when Cocoa needs it.

There’s no “custom NSCell” in Cocoa, though. There’s only cells for text, checkbox (both implemented), popupmenus and buttons (both not implemented).
A TableView can either be NSCell based or NSView based. My work is cell based, because I needed compatibility with OSX 10.6, whereas NSView based requires 10.7.

But even if we’d make a version of the ListBoxTV that is NSView based, I would still have no idea how to enable it so that you could add Xojo Controls to the cells. It would all have to be NSControl based, meaning you’ll have to read the Cocoa docs and do it all by their APIs, as long as MBS has code for it.

So yes, I can add a CellPaint event (which is practically already there, but it’s currently named “WillDisplayCell”). In a NSView based listbox version I could then pass the NSView so that you could add your own subviews using Cocoa API calls.

Also, there is no Graphics object that you could draw with, as the plugin API does not seem to offer one. Meaning that all custom drawing has to be done using NSGraphicsMBS calls.

In the end, if you want more customization and have to learn using Cocoa calls anyway, why not directly use the NSTableView class then, avoiding all the complexity that my ListBoxTV adds?