Re: selecting a single cell in NSTableView?
Re: selecting a single cell in NSTableView?
- Subject: Re: selecting a single cell in NSTableView?
- From: Steve Christensen <email@hidden>
- Date: Sun, 1 Feb 2004 19:09:08 -0800
True, NSMatrix would be convenient in terms of being able to address a
single cell, but I was looking for a NSTableView-based solution for a
couple of reasons:
- I have a number of data sources being displayed in tables, one of
which happens to need by-cell addressing, so it seemed better to try
for a similar display approach; and
- The amount of data involved could be potentially very large (hundreds
of items), so keeping both the model data and the view data at the same
time seemed wasteful, memory-wise.
In any case, I was able to create a NSTable sub-class that allows a
single cell selection without a whole lot of work. I'd hoped that
simply overriding highlightSelectionInClipRect: to clip any
highlighting to only the selected cell would do it, but for some reason
drawRow: was still highlighting the cell backgrounds of the
currently-selected row, so I ended up doing my own version of drawRow:.
I'm not sure that it was the best solution, but everything seems to be
working nicely without too much head scratching.
Thanks for all the info...
steve
On Jan 28, 2004, at 11:01 PM, Daryn wrote:
Using NSMatrix would be far easier than hacking up a table view to
perform your desired behavior.
If you really wanted to hack up a table, I'd override
highlightSelectionInClipRect:. In the mouseDown, calculate the
intersection of rectOfColumn: & rectOfRow:, and then intersect this
against the clipRect in the highlight method.
On Jan 28, 2004, at 11:18 PM, Ramesh PVK wrote:
I'm trying to implement a multi-row, multi-column table where I can
select a single cell in a row instead of the entire row. NSTableView
seems to be very row-oriented in that clicking on one cell selects
the
entire row. Is NSTableView the way to do this, or is there a better
table type class that already does what I want to do? If NSTableView
will do it, what do I need to do to get this behavior?
Yes .Yo can do that .First you need to subclass NSTableView and
override mouseDown: method . With the location of the mouse down you
need to calculate the selected cell row and the column index. Yo can
even give border to the selected cell with the delegate method
tableView:::. I think this is the only way to achieve this.
-(void)mouseDown:(NSEvent *)event
{
selectedRow=[self rowAtPoint:[self convertPoint:[event
locationInWindow] fromView:nil]];
selectedColumn=[[self tableColumns] objectAtIndex:[self
columnAtPoint:[self convertPoint:[event locationInWindow]
fromView:nil]]];
[super mouseDown:event];
}
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell
forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
if(rowIndex==selectedRow && [aTableColumn
isEqualTo:selectedColumn])
[aCell setBordered:YES];
else
[aCell setBordered:NO];
}
--Ramesh
_______________________________________________
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.