Reordered columns and [tableView editColumn:0 row:ind withEvent:nil select:YES];

  • I've got some code that uses editColumn:0 to force the user into edit mode on the first column.

    But I've noticed that if user column reordering is allowed, this no longer edits the correct column. This seems odd to me because I thought Cocoa pretty much shielded the programmer from all the user reordering stuff.

    Even more oddly, if the user puts a checkbox as the first column, the checkbox seems to start behaving like a text box, albeit with invisible characters. Could I be doing something wrong, or is this some kind of bug? And do I have to somehow translate column 0 to find out the real column? I know Java tables have methods to translate between model and view column numbers because of user reordering, but I haven't noticed such a thing in Cocoa.
  • On 08/04/2010, at 11:46 AM, Chris Idou wrote:

    >
    >
    > I've got some code that uses editColumn:0 to force the user into edit mode on the first column.
    >
    > But I've noticed that if user column reordering is allowed, this no longer edits the correct column. This seems odd to me because I thought Cocoa pretty much shielded the programmer from all the user reordering stuff.
    >
    > Even more oddly, if the user puts a checkbox as the first column, the checkbox seems to start behaving like a text box, albeit with invisible characters. Could I be doing something wrong, or is this some kind of bug? And do I have to somehow translate column 0 to find out the real column? I know Java tables have methods to translate between model and view column numbers because of user reordering, but I haven't noticed such a thing in Cocoa.

    Yes, you're doing something wrong. You are assuming that column 0 is always a specific column, which because of user reordering, is not the case.

    Instead of hard-coding 0 as the index of the column, look up its index by [NSTableView columnWithIdentifier:@"foo"]; The identifier is what identifies the column, not its index, so you have to look up the index dynamically.

    --Graham
previous month april 2010 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 29 30    
Go to today