Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/Cocoa Controls/TableView
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin, MBS MacFrameworks Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/Cocoa Controls/TableView
This example is the version from Sun, 17th Mar 2012.
Project "TableView.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control CocoaControlMBS1 Inherits CocoaControlMBS
ControlInstance CocoaControlMBS1 Inherits CocoaControlMBS
EventHandler Function GetView() As NSViewMBS dim i as integer scrollview=new NSScrollViewMBS(0,0,me.Width,me.Height) c1=new MyNSTableColumn("First") c1.Width=200 c2=new MyNSTableColumn("Second") c2.Width=200 d=new MyNSTableDataSource d.c1=c1 d.c2=c2 for i=0 to 9 c1.data(i)=str(i) c2.data(i)=str(i*i) next n=new MyNSTableView(0,0,me.Width,me.Height) n.usesAlternatingRowBackgroundColors=true n.gridStyleMask=n.NSTableViewSolidHorizontalGridLineMask+n.NSTableViewSolidVerticalGridLineMask n.addTableColumn c1 n.addTableColumn c2 n.dataSource=d scrollview.addSubview n Return scrollview End EventHandler
End Control
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
End Control
EventHandler Sub Open() if not CocoaControlMBS1.Available then MsgBox "This example requires Mac OS X 10.5." quit end if End EventHandler
Property c1 As MyNSTableColumn
Property c2 As MyNSTableColumn
Property d As MyNSTableDataSource
Property n As MyNSTableView
Property scrollview As nsscrollViewMBS
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 MyNSTableDataSource Inherits NSTableDataSourceMBS
EventHandler Function numberOfRowsInTableView() As integer Return 10 End EventHandler
EventHandler Function objectValue(column as NSTableColumnMBS, row as integer) As variant if column=c1 then Return c1.data(row) elseif column=c2 then Return c2.data(row) end if End EventHandler
EventHandler Sub setObjectValue(value as variant, column as NSTableColumnMBS, row as integer) if column=c1 then c1.data(row)=value elseif column=c2 then c2.data(row)=value end if End EventHandler
Property c1 As mynsTablecolumn
Property c2 As mynsTablecolumn
End Class
Class MyNSTableColumn Inherits nsTableColumnMBS
Property data(9) As variant
End Class
Class MyNSTableView Inherits NSTableViewMBS
EventHandler Sub ColumnDidMove(notification as NSNotificationMBS, oldColumn as integer, newColumn as integer) log "ColumnDidMove" log " OldColumn: "+str(oldColumn) log " NewColumn: "+str(newColumn) End EventHandler
EventHandler Sub ColumnDidResize(notification as NSNotificationMBS, column as NSTableColumnMBS, index as integer) log "ColumnDidResize" log " index: "+str(index) End EventHandler
EventHandler Sub SelectionDidChange(notification as NSNotificationMBS) log "SelectionDidChange" End EventHandler
EventHandler Sub SelectionIsChanging(notification as NSNotificationMBS) log "SelectionIsChanging" End EventHandler
Sub log(s as string) System.DebugLog s window1.Listbox1.AddRow s End Sub
End Class
End Project

See also:

Feedback, Comments & Corrections

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

MBS Xojo Plugins