Search code examples
nstableviewmonomac

MonoMac TableView not calling GetObjectData


I'm struggling to get the NSTableView working in MonoMac (as a replacement for System.Windows.Forms.ListView), and I'm very puzzled about why my GetObjectData method isn't being called. I've put in debug prints, and the "GetRowCount" method in my NSTableViewSource is being called properly, but it never makes it to GetObjectData. I get a table with the right number of rows, even selection works, but there's no data in the rows. ReloadData also works, in that there's another call to GetRowCount.

Here's the code:

public class MyTableViewSource : NSTableViewSource
{
    //... (constructor, etc.)

    public override int GetRowCount(NSTableView table)
    {
        Debug.Print ("NumberOfRowsInTableView = {0}", mSFList.RowCount);
        return mSFList.RowCount;
    }

    // TODO: Why is this not being called!!!
    public override NSObject GetObjectValue(NSTableView table, NSTableColumn col, int row)
    {
        Debug.Print ("Getting data for row {0}, column titled {1}", row, col.HeaderCell.Title);
        // Get the column index.
        int colIndex;
        NSTableColumn[] cols = table.TableColumns();
        for (colIndex = 0; colIndex < cols.Length; colIndex++)
            if (cols[colIndex] == col) break;
        if (colIndex >= cols.Length) return null;
        return new NSString(mSFList[row,colIndex]);
    }

I even tried forcing things with this Export, but I don't know if I have the string right.

    [Export("tableView:getObjectValue:forTableColumn:row:")]
    public NSObject MyGetObjectValue(NSTableView table, NSTableColumn col, int row)
    {
        return GetObjectValue(table, col, row);
    }

The Debug output is always very consistent:

NumberOfRowsInTableView = 2

Any ideas? I wonder if I did everything right on the XCode side, but I didn't mess with the table, I don't see how I could have blocked this method.

Xamarin Studio 5.5, but I'm keeping Mono at version 3.8.0 for now (3.10 has issues with some Windows code I use).


Solution

  • Following on from my comment above, I retried the whole setup, deleted old tables and inserted new ones and it now works. Though I am using ObjectValueForTableColumn rather than getObjectValue.

    I used the steps provided @ the following link (Credits: Andrew J. Brehm)