# Nicer Listbox for OSX, based on NSTableView (MBS)

**URL:** <https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083>\
**Category:** Extras\
**Created:** [February 13, 2017, 4:09pm UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083 "2017-02-13T16:09:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Tempelmann](https://forum.xojo.com/user_avatar/forum.xojo.com/thomas_tempelmann/32/315_2.png) [@Thomas\_Tempelmann](https://forum.xojo.com/u/Thomas_Tempelmann)\
**Post date:** [February 13, 2017, 4:09pm UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/1 "2017-02-13T16:09:56Z")

</div>

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 [https://www.monkeybreadsoftware.de/xojo/download/plugin/Prerelease/](https://www.monkeybreadsoftware.de/xojo/download/plugin/Prerelease/)

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.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [February 13, 2017, 4:58pm UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/2 "2017-02-13T16:58:11Z")

</div>

Thanks for creating this example.

---

<div class="post-metadata">

**Author:** ![Thomas\_Tempelmann](https://forum.xojo.com/user_avatar/forum.xojo.com/thomas_tempelmann/32/315_2.png) [@Thomas\_Tempelmann](https://forum.xojo.com/u/Thomas_Tempelmann)\
**Post date:** [February 13, 2017, 5:04pm UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/3 "2017-02-13T17:04:40Z")

</div>

Thanks for making it possible, Christian 🙂 (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.)

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [March 6, 2017, 10:34pm UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/4 "2017-03-06T22:34:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thomas\_Tempelmann](https://forum.xojo.com/user_avatar/forum.xojo.com/thomas_tempelmann/32/315_2.png) [@Thomas\_Tempelmann](https://forum.xojo.com/u/Thomas_Tempelmann)\
**Post date:** [March 6, 2017, 11:10pm UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/5 "2017-03-06T23:10:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Thomas\_Tempelmann](https://forum.xojo.com/user_avatar/forum.xojo.com/thomas_tempelmann/32/315_2.png) [@Thomas\_Tempelmann](https://forum.xojo.com/u/Thomas_Tempelmann)\
**Post date:** [March 16, 2017, 4:11pm UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/6 "2017-03-16T16:11:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ChristopheDV](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@ChristopheDV](https://forum.xojo.com/u/ChristopheDV)\
**Post date:** [March 16, 2017, 7:18pm UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/7 "2017-03-16T19:18:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Thomas\_Tempelmann](https://forum.xojo.com/user_avatar/forum.xojo.com/thomas_tempelmann/32/315_2.png) [@Thomas\_Tempelmann](https://forum.xojo.com/u/Thomas_Tempelmann)\
**Post date:** [March 16, 2017, 7:26pm UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/8 "2017-03-16T19:26:48Z")

</div>

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 🙂

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.

---

<div class="post-metadata">

**Author:** ![ChristopheDV](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@ChristopheDV](https://forum.xojo.com/u/ChristopheDV)\
**Post date:** [March 17, 2017, 6:55am UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/9 "2017-03-17T06:55:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [March 17, 2017, 7:00am UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/10 "2017-03-17T07:00:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Thomas\_Tempelmann](https://forum.xojo.com/user_avatar/forum.xojo.com/thomas_tempelmann/32/315_2.png) [@Thomas\_Tempelmann](https://forum.xojo.com/u/Thomas_Tempelmann)\
**Post date:** [March 17, 2017, 8:31am UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/11 "2017-03-17T08:31:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:39pm UTC](https://forum.xojo.com/t/nicer-listbox-for-osx-based-on-nstableview-mbs/36083/12 "2020-10-29T18:39:25Z")

</div>


