Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

/CocoaControls/Listbox and TableView Demos/OutlineControl
Function:
You find this example project in your Plugins Download as a Xojo (Real Studio) project file within the examples folder: /CocoaControls/Listbox and TableView Demos/OutlineControl
This example is the version from Mon, 5th Mar 2017.
Notes: Last modified: Mon, 5th Mar 2017
Project "OutlineControl.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control MyTableControl Inherits HierarchicalMacListBox
ControlInstance MyTableControl Inherits HierarchicalMacListBox
EventHandler Sub Open() // Add two columns dim col as new NSTableColumnMBS("First") col.Width = 200 me.AddColumn col col = new NSTableColumnMBS("Second") col.Width = 120 me.AddColumn col // Set some options to make the list "prettier" me.View.usesAlternatingRowBackgroundColors = true me.View.gridStyleMask = NSTableViewMBS.NSTableViewSolidHorizontalGridLineMask+NSTableViewMBS.NSTableViewSolidVerticalGridLineMask // Specify the column that contains the "expand" icons. If we don't set this, we effectively get a flat list instead dim cols() as NSTableColumnMBS = me.View.tableColumns() me.View.outlineTableColumn = cols(0) ' use the first column // If we want to allow column resizing, this option should be set to avoid ugly visual effect while resizing // (i.e. the vertical grid lines do not move nicely, then), or the gridlines should be not used. me.View.autoresizesOutlineColumn = false // Set up our hierarchical data, which is a tree structure mRootItem = new DataNode ("root") for level1 as Integer = 1 to 30 dim node as new DataNode (Str(level1)) mRootItem.children.Append node ' let's give each node a few children for level2 as Integer = 1 to level1 dim node2 as new DataNode (node.text + " - " + Str(level2)) node.children.Append node2 ' let's give each of these nodes a few children as well for level3 as Integer = 1 to 3 'Rnd*5 dim node3 as new DataNode (node.text + " - " + Str(level3)) node2.children.Append node3 next next next me.Reload ' this forces the listbox to update (by calling Events such as childOfItem etc.) End EventHandler
EventHandler Function childOfItem(index as Integer, item as NSOutlineViewItemMBS) As NSOutlineViewItemMBS #pragma DisableBoundsChecking #pragma DisableBackgroundTasks #pragma StackOverflowChecking false 'mCallCount = mCallCount + 1 dim node as DataNode if item = nil then node = mRootItem else node = DataNode(item) end if return node.children(index) End EventHandler
EventHandler Function isItemExpandable(item as NSOutlineViewItemMBS) As Boolean #pragma DisableBoundsChecking #pragma DisableBackgroundTasks #pragma StackOverflowChecking false mCallCount = mCallCount + 1 dim node as DataNode if item = nil then node = mRootItem else node = DataNode(item) end if return node.children.Ubound >= 0 End EventHandler
EventHandler Function numberOfChildrenOfItem(item as NSOutlineViewItemMBS) As integer #pragma DisableBoundsChecking #pragma DisableBackgroundTasks #pragma StackOverflowChecking false 'mCallCount = mCallCount + 1 dim node as DataNode if item = nil then node = mRootItem else node = DataNode(item) end if if node <> nil then return node.children.Ubound+1 end if End EventHandler
EventHandler Function objectValue(tableColumn as NSTableColumnMBS, item as NSOutlineViewItemMBS) As Variant #pragma DisableBoundsChecking #pragma DisableBackgroundTasks #pragma StackOverflowChecking false 'mCallCount = mCallCount + 1 dim node as DataNode if item = nil then node = mRootItem else node = DataNode(item) end if return node.text End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Label1.Text = Str (mCallCount) + " (" + Str(MyTableControl.View.numberOfRows) + " rows)" mCallCount = 0 End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Property Private mCallCount As Integer
Property Private mRootItem As DataNode
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class HierarchicalMacListBox Inherits NSOutlineControlMBS
Sub AddColumn(col as NSTableColumnMBS) mRetainedCols.Append col me.View.addTableColumn col End Sub
Sub Reload() me.View.reloadData End Sub
Property Private mRetainedCols() As NSTableColumnMBS
End Class
Class DataNode Inherits NSOutlineViewItemMBS
Sub Constructor(text as String) me.text = text super.Constructor End Sub
Property children() As NSOutlineViewItemMBS
Property text As String
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS CocoaControls Plugin.




Links
MBS Xojo Plugins