NSMatrix - Selecting multiple cells programmatically

  • Well, I thought this would be an easy one but I just can't figure it out.  I
    have an NSMatrix of button cells in list mode.  Therefore, the user can
    select multiple cells using a pattern like the finder (shift-click for a
    range of cells and alt-click for multiple individual cells).  The problem
    arises when trying to do the second case in code.

    The various selectCell methods always unselect the previous cell (like a
    regular click).  I tried using setSelectionFrom:to:anchor:highlight but
    can't get it to select anything but a continuous range.

    Simplest case: Given a matrix of three cells is list mode, how can you
    select the first and third in code?

    I will be very appreciative of anyone with the answer since this has already
    gobbled up huge amounts of time.

    Jason Bell
  • Please! can someone help figure this out. I gave up months ago (after
    posting an identical question). I got no response that solved this
    actual problem.

    The one response suggested manually setting each cells highlight state
    (which works although without affecting [matrix selectedCells] output).
    Then use an NSMatrix subclass to manage selection yourself (or maybe a
    delegate depending on how/where your code needs to know which cells are
    selected).

    I didn't like this solution cause it just seems wrong. NSMatrix should
    allow programmatically selecting multiple cells with something simple
    (maybe selectCells:). But it doesn't. NSMatrix was made public 12+ years
    ago, someone must have figured this out.

    BTW. Breaking on setState: when using an alt-click to select a second
    cell results in this backtrace (none of these 6 "_" prefixed methods is
    public):
    #0  -[JimBrowserCell setState:]
    #1  0x70d36384 in -[NSMatrix _selectRange::::] ()
    #2  0x70d36594 in -[NSMatrix _selectRectRange::] ()
    #3  0x70d3725c in -[NSMatrix _setSelectionRange::] ()
    #4  0x70d34808 in -[NSMatrix _mouseLoop::::::] ()
    #5  0x70d37410 in -[NSMatrix _shiftDown::::] ()
    #6  0x70d332a4 in -[NSMatrix _mouseDownListmode:] ()
    #7  0x70d3ae7c in -[NSMatrix mouseDown:] ()

      -jim

    On Saturday, February 23, 2002, at 04:57 AM, Jason R. Bell wrote:

    > Well, I thought this would be an easy one but I just can't figure it
    > out.  I
    > have an NSMatrix of button cells in list mode.  Therefore, the user can
    > select multiple cells using a pattern like the finder (shift-click for a
    > range of cells and alt-click for multiple individual cells).  The
    > problem
    > arises when trying to do the second case in code.
    >

    _________________________________________________________
    Do You Yahoo!?
    Get your free @yahoo.com address at http://mail.yahoo.com
  • Here is what I learned when trying to figure out how to select multiple
    cells in a matrix (in list mode).

    Given a matrix of six cells (three columns and two rows).

    // Highlights a range of cells (first, second, forth, and fifth)
    [matrix setSelectionFrom:0 to:4 anchor:0 highlight:YES];

    // Highlight the first and third cell
    [matrix setSelectionFrom:0 to:0 anchor:0 highlight:YES];
    [matrix setSelectionFrom:2 to:2 anchor:2 highlight:YES];

    setSelection does not clear the currently selected cells, so I also call
    deslectAllCells before selecting the cells I want in code.  There's no doubt
    that the docs could do a better job of explaining the anchor parameter.

    - Jason Bell

    On 2/26/02 12:47 AM, "James DiPalma" <jamesdipalma...> wrote:

    > Please! can someone help figure this out. I gave up months ago (after
    > posting an identical question). I got no response that solved this
    > actual problem.
    >
    > The one response suggested manually setting each cells highlight state
    > (which works although without affecting [matrix selectedCells] output).
    > Then use an NSMatrix subclass to manage selection yourself (or maybe a
    > delegate depending on how/where your code needs to know which cells are
    > selected).
    >
    > I didn't like this solution cause it just seems wrong. NSMatrix should
    > allow programmatically selecting multiple cells with something simple
    > (maybe selectCells:). But it doesn't. NSMatrix was made public 12+ years
    > ago, someone must have figured this out.
    >
    > BTW. Breaking on setState: when using an alt-click to select a second
    > cell results in this backtrace (none of these 6 "_" prefixed methods is
    > public):
    > #0  -[JimBrowserCell setState:]
    > #1  0x70d36384 in -[NSMatrix _selectRange::::] ()
    > #2  0x70d36594 in -[NSMatrix _selectRectRange::] ()
    > #3  0x70d3725c in -[NSMatrix _setSelectionRange::] ()
    > #4  0x70d34808 in -[NSMatrix _mouseLoop::::::] ()
    > #5  0x70d37410 in -[NSMatrix _shiftDown::::] ()
    > #6  0x70d332a4 in -[NSMatrix _mouseDownListmode:] ()
    > #7  0x70d3ae7c in -[NSMatrix mouseDown:] ()
    >
    >
    >
    > -jim
    >
    >
    > On Saturday, February 23, 2002, at 04:57 AM, Jason R. Bell wrote:
    >
    >> Well, I thought this would be an easy one but I just can't figure it
    >> out.  I
    >> have an NSMatrix of button cells in list mode.  Therefore, the user can
    >> select multiple cells using a pattern like the finder (shift-click for a
    >> range of cells and alt-click for multiple individual cells).  The
    >> problem
    >> arises when trying to do the second case in code.
    >>
    >
    >
    > _________________________________________________________
    > Do You Yahoo!?
    > Get your free @yahoo.com address at http://mail.yahoo.com
    >
previous month february 2002 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28      
Go to today