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