tomitrescak
tomitrescak

Reputation: 1110

MonoMac events - Changing Color of NSTable row

I am trying to change row color in NSTableView by subscribing to WillDisplayCell event. First, this event is never raised. Second, the fields in the NSTableView are no longer selectable, thus functionality is broken. Same behavior can be observed for SelectionChanged event which does not work.

//NSTableView table
table.SelectionDidChange += SelectionChanged;
table.WillDisplayCell += WillDisplay;

How to make these events work?

Thank you!

Upvotes: 3

Views: 362

Answers (2)

Radu Simionescu
Radu Simionescu

Reputation: 4695

in AwakeFromNib register observer like so

NSNotificationCenter.DefaultCenter.AddObserver (this, new Selector ("selectionChanged"), "NSTableViewSelectionDidChangeNotification", yourTableView);

Then handle selection change like so

[Export("selectionChanged")]
public void SelectionDidChangeNotification(NSObject o){
    ...
}

Upvotes: 0

eaglestorm
eaglestorm

Reputation: 1202

Not sure if you solved this or not but for anyone else who comes across this the solution is to add an observer similar to the tableview example, i.e.

arrayController.AddObserver(this,new NSString("selectionIndexes"),NSKeyValueObservingOptions.New,IntPtr.Zero);

Then override the observe value method

public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
{
...
}

This works but the NSTableviewBinding example uses a different method but that didn't work for me.

Upvotes: 1

Related Questions