[Mono-osx] NSTableView in monomac

Duane Wandless duane at wandless.net
Fri Aug 20 08:52:32 EDT 2010


That depends on what theValue really is.  What kind of objects are stored in
the ArrayList?  Are they derived from NSObject?  If no, then that cast is
invalid.

For example, if you are storing strings in the ArrayList you will need to
return new NSString(theValue).

Also have you looked at using NSTableViewDataSource?  Easier than writing
the delegate functions by hand.

Duane

On Fri, Aug 20, 2010 at 8:03 AM, <gareth.baker at stfc.ac.uk> wrote:

>  Hi,
>
>
>
> I’m trying to use an NSTableView from monomac. I can get the code to
> compile with the two delegate functions:
>
>
>
>          [Export("numberOfRowsInTableView:")]
>
>           public int GetRowCount(NSTableView aTableView)
>
>           {
>
>             return records.Count;// records is an ArrayList
>
>       }
>
>
>
>             [Export("tableView:objectValueForTableColumn:row:")]
>
>       public NSObject GetObjectValue(NSTableView aTableView, NSTableColumn
> aTableColumn, int rowIndex)
>
>       {
>
>             string identifier = aTableColumn.Identifier.ToString();
>
>             Object theRecord, theValue;
>
>
>
>                   theRecord = records[rowIndex];
>
>                   theValue = ((Hashtable)theRecord)[identifier];
>
>
>
>             return (NSObject)theValue;// this cast is not working
>
>       }
>
>
>
> Running the program crashes when I try to add data to the TableView. Using
> the debugger seems to indicate that all is well up to the ‘return’ in
> GetObjectValue when the cast fails with “Unhandled Exception:
> System.InvalidCastException: Cannot cast from source to destination type”.
> Is this the correct way to do this cast?
>
>
>
> Thanks
>
> Gareth Baker
>
>
>
> --
> Scanned by iCritical.
>
>
> _______________________________________________
> Mono-osx mailing list
> Mono-osx at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-osx
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20100820/b6adb637/attachment.html 


More information about the Mono-osx mailing list