Application Icon in Listbox


In a Listbox I am attempting to draw the application icon together with the corresponding application name. When inserting the code below in the CellBackgroundPaint event of the listbox, I get the generic file icon for all application names, bur not the individual icons:

Dim f As FolderItem
Dim Icon as Picture
f = GetFolderItem(Path)
dim n as NSImageMBS = NSWorkspaceMBS.iconForFile(f)
n.size = new NSSizeMBS(16,16)
Icon = n.CopyPictureWithMask

However, when I insert the above code in the Paint event of a canvas, the desired icon is drawn.

I have searched all examples, for both Xojo and for MBS, but have found no solution to the problem.
Any help will be greatly appreciated.


What is path?

path is the path to the application.


Use the RowPicture mechanism.

For example:

       Me.RowPicture(Me.LastIndex) = f.Item(x).IconMBS(16)

I’m sorry, Tim, This still gives me only the generic icon, not the icon for the particular application.

Thanks anyway,


brute force idea:

why don’t you get the application icon from where it is stored:

<appl-name>/Contents/Resources/<appl-name.icns> (for OS X)

Hi Emile,

The problem isn’t getting the image, as you may see from the code in my original question. The icon obtained in this way draws nicely when invoked from the Paint event of a Canvas. However, when this code is applied to a Listbox, only the generic icon for a file is drawn.


Just an idea : have you tried to load the icon first into a canvas, and then lift it from there to insert it into a cell ?

I support Michel motion !

Very odd as I get the specified app’s icon every time.

Could you post the code from your listbox around the RowPicture call?

I’m giving up. - Who wants them darned icons anyway?


Try this:

Private Function GetApplicationIcon(theBundleIdentifier as String) As NSImageMBS

dim theApp as FolderItem = LaunchServicesFindApplicationForInfoMBS("", theBundleIdentifier,"")
if theApp = nil then Return nil
if RetinaScaleFactor = 0 then RetinaScaleFactor = globals.getRetinaScalingFactor(self.Window)

dim theNSImage as NSImageMBS = NSWorkspaceMBS.iconForFile(theApp)
if RetinaScaleFactor = 1 then
theNSImage.size = new NSSizeMBS(16, 16)
theNSImage.size = new NSSizeMBS(32, 32)
end if
return theNSImage

End Function

You only need to convert from NSImage to picture.