table view with non-selectable rows

  • Hi all.

    I have got a problem with a table view.

    What I want:

    A table view which does not highlight rows but allows the user to
    klick checkboxes in a column of said table view.

    Picture:As you can see I already managed to remove the background.

    To avoid the rows from highlighting, I tried to implement the -
    tableView:shouldSelectRow: delegate method and prevent the user from
    selecting a row. But if I do so, it is no longer possible to change
    the value of the check box in the first column.

    After some experimentation I found a method that *almost* works. I do
    overwrite -_highlightColorForCell: and return [[self window]
    backgroundColor].

    This has two drawbacks:

    1. _highlightColorForCell: is a private method that I really
    shouldn't overwrite at all

    2. NSTableView's highlighting code seems to assume that a highlighted
    row is opaque. But I'm using that table view inside a sheet which is
    slightly transparent. So - depending on the contents of the window
    below - a highlighted row does still look different from the not
    highlighted one because it draws its background opaque.

    Any solutions, anyone?

    Andreas
  • On Oct 15, 2005, at 1:31 PM, Andreas Mayer wrote:

    > Hi all.
    >
    > I have got a problem with a table view.
    >
    > What I want:
    >
    > A table view which does not highlight rows but allows the user to
    > klick checkboxes in a column of said table view.
    >
    > Picture:
    >
    >
    > <tableview.png>
    >
    > As you can see I already managed to remove the background.
    >
    > To avoid the rows from highlighting, I tried to implement the -
    > tableView:shouldSelectRow: delegate method and prevent the user
    > from selecting a row. But if I do so, it is no longer possible to
    > change the value of the check box in the first column.
    >

    Maybe that's ok; you could check the mouse position to see if it's in
    the column w/ checkboxes and change the state of the checkboxes
    yourself.

    > After some experimentation I found a method that *almost* works. I
    > do overwrite -_highlightColorForCell: and return [[self window]
    > backgroundColor].
    >
    > This has two drawbacks:
    >
    > 1. _highlightColorForCell: is a private method that I really
    > shouldn't overwrite at all
    >
    > 2. NSTableView's highlighting code seems to assume that a
    > highlighted row is opaque. But I'm using that table view inside a
    > sheet which is slightly transparent. So - depending on the contents
    > of the window below - a highlighted row does still look different
    > from the not highlighted one because it draws its background opaque.
    >
    > Any solutions, anyone?
    >

    Have you tried overriding highlightSelectionInClipRect:?
  • Am 16.10.2005 um 18:17 Uhr schrieb Ryan Stevens:

    > Maybe that's ok; you could check the mouse position to see if it's
    > in the column w/ checkboxes and change the state of the checkboxes
    > yourself.

    Thanks for the suggestion. I ended up implementing an action method
    for the table view, which is called even if I do not allow a
    selection. This somewhat defeats the purpose of using a table view
    and bindings though. :-/

    > Have you tried overriding highlightSelectionInClipRect:?

    Yes. Didn't change anything. No idea what that method is supposed to do.

    Andreas
  • >
    > A table view which does not highlight rows but allows the user to
    > klick checkboxes in a column of said table view.

    I have many requests for this ability. Eventually, it will be easier
    to do.

    >
    > To avoid the rows from highlighting, I tried to implement the -
    > tableView:shouldSelectRow: delegate method and prevent the user from
    > selecting a row. But if I do so, it is no longer possible to change
    > the value of the check box in the first column.

    Yes -- this is one of the problems. In order for tableview to "track"
    a cell, the row has to be selected. Eventually, this limitation may be
    changed, allowing one to still select rows, and still click on other
    checkboxes without changing the selection. For now, that ability is
    rather difficult to achieve without rewriting "mouseDown:".

    >
    > After some experimentation I found a method that *almost* works. I
    > do overwrite -_highlightColorForCell: and return [[self window]
    > backgroundColor].
    >

    Okay, a few things. Don't override the private method! How did you
    find out that overriding this method would work?

    Instead, you should subclass your cell, and override:

    - (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView
    *)controlView;

    return nil, and the highlight won't be drawn.

    > This has two drawbacks:
    >
    > 1. _highlightColorForCell: is a private method that I really
    > shouldn't overwrite at all

    Yes.

    >
    > 2. NSTableView's highlighting code seems to assume that a
    > highlighted row is opaque. But I'm using that table view inside a
    > sheet which is slightly transparent. So - depending on the contents
    > of the window below - a highlighted row does still look different
    > from the not highlighted one because it draws its background opaque.

    I'm pretty sure that using a nil color will give you what you want. If
    not, please let me know more about what you are seeing vs. what you
    expect.
    thanks,
    corbin