• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re:(new problem) Selecting item in NSTableView when right-clicked on...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:(new problem) Selecting item in NSTableView when right-clicked on...


  • Subject: Re:(new problem) Selecting item in NSTableView when right-clicked on...
  • From: Glenn Andreas <email@hidden>
  • Date: Mon, 25 Aug 2003 18:26:54 -0500

On mendag, aug 25, 2003, at 17:41 Europe/Stockholm, Nils Hjelte wrote:

I have an NSTableView with an contextmenu attached to it. When the user right-clicks on an item in the NSTableView the contextmenu is brought up correctly, but I also want the clicked cell to be selected. Is there some cleaner/better way of doing this than to subclass NSTableView and tracking mouse events?

// Nils Hjelte

Ok, so I subclassed NSTableView and implemented the rightMouseDown method. To select the row I simulate a left-mouseclick and then continue with the right-mouseclick. The method looks like this:

- (void)rightMouseDown:(NSEvent *)theEvent
{
/* Simulate a click with left mouse button to select row */
[super mouseDown:theEvent];
[super mouseUp:theEvent];
/* Continue with right-click to bring up context-menu */
[super rightMouseDown:theEvent];
}

This doesn't work though. The problem is when I right-click an item in the table view it correctly selects the item, but it doesn't bring up the context-menu until I make a new left-click in the table view. What should I do?

Try overring "menuForEvent:" (a method of NSResponder) in your subclass and select the row there:

- (NSMenu *)menuForEvent:(NSEvent *)theEvent;
{
// what row are we at?
int row = [self rowAtPoint: [self convertPoint: [theEvent locationInWindow] fromView: nil]];
if (row != -1) {
[self selectRow: row byExtendingSelection: NO];
}
return [super menu]; // use what we've got
}

Glenn Andreas email@hidden
Author of Macintosh games: Theldrow 2.3, Blobbo 1.0.2, Cythera 1.0.2
Be good, and you will be lonesome
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re:(new problem) Selecting item in NSTableView when right-clicked on... (From: Nils Hjelte <email@hidden>)

  • Prev by Date: Re: Page Breaks in NSTextViews
  • Next by Date: Re: logical (! object) vs (object != nil)
  • Previous by thread: Re:(new problem) Selecting item in NSTableView when right-clicked on...
  • Next by thread: Re: Page Breaks in NSTextViews
  • Index(es):
    • Date
    • Thread