NSComboBox and bindings

  • Hi list,

      Am I doing something wrong or is this a bug?  The following is
    reduced to the simplest I can make it.

    I have a NSComboBox a NSArrayController and a model class with a "name"
    instance variable with KVC compliant accessors.  I have set the
    following:

    NSArrayController's - Object Class Name: to the model class
    NSComboBox's bindings to:-
    content ->
          BindTo: NSArrayController
          Controller Key: arrangedObjects
          Model Key Path:

    contentValues ->
          BindTo: NSArrayController
          Controller Key: arrangedObjects
          Model Key Path: name

    value->
          BindTo: NSArrayController
          Controller Key: selection (Note: have tried all other combinations
    as well)
          Model Key Path: name

    I also have an Add button hooked up to the Add: action method on
    NSArrayController
    Repeat 3X {
          Hit Add, edit the combo field followed by <cr>
    }
    If I drop down the list I have, for example

    Item1
    Item2
    Item3  <- this is highlighted as it was the last item entered

    If I NSLog() the contents of the NSArrayController I get the same three
    strings - everything OK so far!
    Now if I select Item1 from the list, for example, the text field shows
    Item1 as expected but if I drop the list down again I have

    Item1
    Item2
    Item1

    if I output the contents of the NSArrayController I also have the above.
    It would seem that the NSArrayController is updating the last selected
    position but with the newly selected list item.
    A bug or just me?

    Thanks
    David
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • I see exactly the same problem. I didn't see any answer of this
    posting. Have anyone an answer to this?

    Ivan

    Pe 17. des. 2003 kl. 23.28 skrev David Webster:

    > Hi list,
    >
    > Am I doing something wrong or is this a bug?  The following is
    > reduced to the simplest I can make it.
    >
    > I have a NSComboBox a NSArrayController and a model class with a
    > "name" instance variable with KVC compliant accessors.  I have set the
    > following:
    >
    > NSArrayController's - Object Class Name: to the model class
    > NSComboBox's bindings to:-
    > content ->
    > BindTo: NSArrayController
    > Controller Key: arrangedObjects
    > Model Key Path:
    >
    > contentValues ->
    > BindTo: NSArrayController
    > Controller Key: arrangedObjects
    > Model Key Path: name
    >
    > value->
    > BindTo: NSArrayController
    > Controller Key: selection (Note: have tried all other
    > combinations as well)
    > Model Key Path: name
    >
    > I also have an Add button hooked up to the Add: action method on
    > NSArrayController
    > Repeat 3X {
    > Hit Add, edit the combo field followed by <cr>
    > }
    > If I drop down the list I have, for example
    >
    > Item1
    > Item2
    > Item3  <- this is highlighted as it was the last item entered
    >
    > If I NSLog() the contents of the NSArrayController I get the same
    > three strings - everything OK so far!
    > Now if I select Item1 from the list, for example, the text field shows
    > Item1 as expected but if I drop the list down again I have
    >
    > Item1
    > Item2
    > Item1
    >
    > if I output the contents of the NSArrayController I also have the
    > above.
    > It would seem that the NSArrayController is updating the last selected
    > position but with the newly selected list item.
    > A bug or just me?
    >
    > Thanks
    > David
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    >
    >
    Ivan C Myrvold
    OrtopediService AS
    Mob. 913 16 356
    Tlf. 38 14 45 93
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On May 26, 2004, at 7:02 AM, Ivan Myrvold wrote:

    >> value->
    >> BindTo: NSArrayController
    >> Controller Key: selection (Note: have tried all other
    >> combinations as well)
    >> Model Key Path: name
    >>
    Why is this bound to the same array controller as that which provides
    the content array?  It would make more sense for it to be bound to
    another controller that represents the object whose attribute you want
    to set?  If you do that it seems to work fine...

    mmalc
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • The problem is that a combo box is not a popup menu:

    A popup menu represents a choice of an immutable value from an
    immutable array of choices.

    A combo box represents an arbitrary value, which is coordinated with an
    array of choices, which the programmer may make mutable -- for instance
    by adding each new entry in the field to the array. There is no
    question of selecting an indexed member of the list, as it is
    permissible to enter a string that isn't a member of the list.

    Binding the value of an NSComboBox to a property of an
    NSArrayController's selection would therefore be expected to edit the
    property of the selected item itself. It's hard to see what else to
    expect, as the mutability and content of the contentValues are at the
    option of the programmer.

    The experiment that I found works is:
    -- Bind the contentValues to arrangedObjects.name
    -- Bind the value to some property of the NSObjectController that owns
    the array from which the arrangedObjects were drawn. This has to be
    independent of the array and the selection of the NSArrayController,
    because (I repeat) NSComboBox doesn't really deal in selection from a
    list except as a convenience in filling in a text field. It's a text
    field, not a menu.
    -- In the setter method for the value property, modify the
    contentValues array, if desired.

    -- F

    On 26 May 2004, at 9:02 AM, Ivan Myrvold wrote:

    > I see exactly the same problem. I didn't see any answer of this
    > posting. Have anyone an answer to this?
    >
    > Ivan
    >
    > Pe 17. des. 2003 kl. 23.28 skrev David Webster:
    >
    >> Hi list,
    >>
    >> Am I doing something wrong or is this a bug?  The following is
    >> reduced to the simplest I can make it.
    >>
    >> I have a NSComboBox a NSArrayController and a model class with a
    >> "name" instance variable with KVC compliant accessors.  I have set
    >> the following:
    >>
    >> NSArrayController's - Object Class Name: to the model class
    >> NSComboBox's bindings to:-
    >> content ->
    >> BindTo: NSArrayController
    >> Controller Key: arrangedObjects
    >> Model Key Path:
    >>
    >> contentValues ->
    >> BindTo: NSArrayController
    >> Controller Key: arrangedObjects
    >> Model Key Path: name
    >>
    >> value->
    >> BindTo: NSArrayController
    >> Controller Key: selection (Note: have tried all other
    >> combinations as well)
    >> Model Key Path: name
    >>
    >> I also have an Add button hooked up to the Add: action method on
    >> NSArrayController
    >> Repeat 3X {
    >> Hit Add, edit the combo field followed by <cr>
    >> }
    >> If I drop down the list I have, for example
    >>
    >> Item1
    >> Item2
    >> Item3  <- this is highlighted as it was the last item entered
    >>
    >> If I NSLog() the contents of the NSArrayController I get the same
    >> three strings - everything OK so far!
    >> Now if I select Item1 from the list, for example, the text field
    >> shows Item1 as expected but if I drop the list down again I have
    >>
    >> Item1
    >> Item2
    >> Item1
    >>
    >> if I output the contents of the NSArrayController I also have the
    >> above.
    >> It would seem that the NSArrayController is updating the last
    >> selected position but with the newly selected list item.
    >> A bug or just me?
    >>
    >> Thanks
    >> David
    >> _______________________________________________
    >> cocoa-dev mailing list | <cocoa-dev...>
    >> Help/Unsubscribe/Archives:
    >> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    >> Do not post admin requests to the list. They will be ignored.
    >>
    >>
    > Ivan C Myrvold
    > OrtopediService AS
    > Mob. 913 16 356
    > Tlf. 38 14 45 93
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • My problem was that I really didn't understand the meanings of content,
    contentValues and values. Your help have given these value selections
    more meaning to me, and I think I understand this better now. The
    bricks seems to have fallen into place. Thank you again.

    Ivan

    Pe 26. mai. 2004 kl. 18.48 skrev Fritz Anderson:

    > The problem is that a combo box is not a popup menu:
    >
    > A popup menu represents a choice of an immutable value from an
    > immutable array of choices.
    >
    > A combo box represents an arbitrary value, which is coordinated with
    > an array of choices, which the programmer may make mutable -- for
    > instance by adding each new entry in the field to the array. There is
    > no question of selecting an indexed member of the list, as it is
    > permissible to enter a string that isn't a member of the list.
    >
    > Binding the value of an NSComboBox to a property of an
    > NSArrayController's selection would therefore be expected to edit the
    > property of the selected item itself. It's hard to see what else to
    > expect, as the mutability and content of the contentValues are at the
    > option of the programmer.
    >
    > The experiment that I found works is:
    > -- Bind the contentValues to arrangedObjects.name
    > -- Bind the value to some property of the NSObjectController that
    > owns the array from which the arrangedObjects were drawn. This has to
    > be independent of the array and the selection of the
    > NSArrayController, because (I repeat) NSComboBox doesn't really deal
    > in selection from a list except as a convenience in filling in a text
    > field. It's a text field, not a menu.
    > -- In the setter method for the value property, modify the
    > contentValues array, if desired.
    >
    > -- F
    >
    >
    > On 26 May 2004, at 9:02 AM, Ivan Myrvold wrote:
    >
    >> I see exactly the same problem. I didn't see any answer of this
    >> posting. Have anyone an answer to this?
    >>
    >> Ivan
    >>
    >> Pe 17. des. 2003 kl. 23.28 skrev David Webster:
    >>
    >>> Hi list,
    >>>
    >>> Am I doing something wrong or is this a bug?  The following is
    >>> reduced to the simplest I can make it.
    >>>
    >>> I have a NSComboBox a NSArrayController and a model class with a
    >>> "name" instance variable with KVC compliant accessors.  I have set
    >>> the following:
    >>>
    >>> NSArrayController's - Object Class Name: to the model class
    >>> NSComboBox's bindings to:-
    >>> content ->
    >>> BindTo: NSArrayController
    >>> Controller Key: arrangedObjects
    >>> Model Key Path:
    >>>
    >>> contentValues ->
    >>> BindTo: NSArrayController
    >>> Controller Key: arrangedObjects
    >>> Model Key Path: name
    >>>
    >>> value->
    >>> BindTo: NSArrayController
    >>> Controller Key: selection (Note: have tried all other
    >>> combinations as well)
    >>> Model Key Path: name
    >>>
    >>> I also have an Add button hooked up to the Add: action method on
    >>> NSArrayController
    >>> Repeat 3X {
    >>> Hit Add, edit the combo field followed by <cr>
    >>> }
    >>> If I drop down the list I have, for example
    >>>
    >>> Item1
    >>> Item2
    >>> Item3  <- this is highlighted as it was the last item entered
    >>>
    >>> If I NSLog() the contents of the NSArrayController I get the same
    >>> three strings - everything OK so far!
    >>> Now if I select Item1 from the list, for example, the text field
    >>> shows Item1 as expected but if I drop the list down again I have
    >>>
    >>> Item1
    >>> Item2
    >>> Item1
    >>>
    >>> if I output the contents of the NSArrayController I also have the
    >>> above.
    >>> It would seem that the NSArrayController is updating the last
    >>> selected position but with the newly selected list item.
    >>> A bug or just me?
    >>>
    >>> Thanks
    >>> David
    >>> _______________________________________________
    >>> cocoa-dev mailing list | <cocoa-dev...>
    >>> Help/Unsubscribe/Archives:
    >>> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    >>> Do not post admin requests to the list. They will be ignored.
    >>>
    >>>
    >> Ivan C Myrvold
    >> OrtopediService AS
    >> Mob. 913 16 356
    >> Tlf. 38 14 45 93
    >> _______________________________________________
    >> cocoa-dev mailing list | <cocoa-dev...>
    >> Help/Unsubscribe/Archives:
    >> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    >> Do not post admin requests to the list. They will be ignored.
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • I have mostly got the bindings for NSComboBox working now. If I select
    a title from the list, the title is stored in my setter method. I want
    the value (stored in a different array) to be stored instead.

    I have a model object (oppgave_combo) with an access method
    (displayarray) which returns an array of strings to be displayed as the
    items in the NSComboBox.
    The same model object have another method (valuearray) which returns
    the values to be stored as a result of selecting an item.
    This last one I don't quite know how to bind to the NSComboBox.

    Value Selection: (of the NSComboBox's binding):

    > content = oppgave_combo.displayarray [File's Owner
    (MyWindowController)]
    > contentValues
    > value = oppgave_combo.value [File's Owner (MyWindowController)]

    This works fine, The NSComboBox is populated with the displayarray, and
    selecting an item sets the instance variable "value" of the model
    object "oppgave_combo".

    But how do I bind the NSComboBox, so that the values stored in the
    _valuearray is stored instead of the title?

    I tried to bind contentValues like this:
    > contentValues = oppgave_combo.valuearray [File's Owner
    (MyWindowController)], but then I get the following message:

    2004-05-27 11:18:12.926 Partos[5585] Binding contentValues of object
    <NSComboBox: 0x7fcfac0> ignored: Key path (currently bound as
    oppgave_combo.valuearray) needs to have the content key path
    (oppgave_combo.displayarray) as prefix
    2004-05-27 11:18:12.978 Partos[5585] Binding contentValues of object
    <NSComboBox: 0x7fcfac0> ignored: Key path (currently bound as
    oppgave_combo.valuearray) needs to have the content key path
    (oppgave_combo.displayarray) as prefix

    Pe 26. mai. 2004 kl. 18.48 skrev Fritz Anderson:

    > The experiment that I found works is:
    > -- Bind the contentValues to arrangedObjects.name
    > -- Bind the value to some property of the NSObjectController that
    > owns the array from which the arrangedObjects were drawn. This has to
    > be independent of the array and the selection of the
    > NSArrayController, because (I repeat) NSComboBox doesn't really deal
    > in selection from a list except as a convenience in filling in a text
    > field. It's a text field, not a menu.
    > -- In the setter method for the value property, modify the
    > contentValues array, if desired.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On 2004-05-27, at 11.23, Ivan Myrvold wrote:

    > I have mostly got the bindings for NSComboBox working now. If I select
    > a title from the list, the title is stored in my setter method. I want
    > the value (stored in a different array) to be stored instead.
    >
    > I have a model object (oppgave_combo) with an access method
    > (displayarray) which returns an array of strings to be displayed as
    > the items in the NSComboBox.
    > The same model object have another method (valuearray) which returns
    > the values to be stored as a result of selecting an item.
    > This last one I don't quite know how to bind to the NSComboBox.
    >
    > Value Selection: (of the NSComboBox's binding):
    >
    >> content = oppgave_combo.displayarray [File's Owner
    > (MyWindowController)]
    >> contentValues
    >> value = oppgave_combo.value [File's Owner (MyWindowController)]
    >
    > This works fine, The NSComboBox is populated with the displayarray,
    > and selecting an item sets the instance variable "value" of the model
    > object "oppgave_combo".
    >
    > But how do I bind the NSComboBox, so that the values stored in the
    > _valuearray is stored instead of the title?
    >
    > I tried to bind contentValues like this:
    >> contentValues = oppgave_combo.valuearray [File's Owner
    > (MyWindowController)], but then I get the following message:
    >
    > 2004-05-27 11:18:12.926 Partos[5585] Binding contentValues of object
    > <NSComboBox: 0x7fcfac0> ignored: Key path (currently bound as
    > oppgave_combo.valuearray) needs to have the content key path
    > (oppgave_combo.displayarray) as prefix
    > 2004-05-27 11:18:12.978 Partos[5585] Binding contentValues of object
    > <NSComboBox: 0x7fcfac0> ignored: Key path (currently bound as
    > oppgave_combo.valuearray) needs to have the content key path
    > (oppgave_combo.displayarray) as prefix
    >

    With contentValues you select the attribute of the objects in your
    array that you what to be displayed in the NSComboBox. So the error
    means that it can't find the attribute "oppgave_combo.valuearray" in
    the objects (NSString objects I assume) in your array
    oppgave_combo.displayarray.

    I think that the only way you can use your valuearray is by creating an
    outlet in oppgave_combo and connect it to your combo box and go from
    there. As Fritz said below " It's a text field, not a menu".

    Joakim
    >
    >
    > Pe 26. mai. 2004 kl. 18.48 skrev Fritz Anderson:
    >
    >> The experiment that I found works is:
    >> -- Bind the contentValues to arrangedObjects.name
    >> -- Bind the value to some property of the NSObjectController that
    >> owns the array from which the arrangedObjects were drawn. This has to
    >> be independent of the array and the selection of the
    >> NSArrayController, because (I repeat) NSComboBox doesn't really deal
    >> in selection from a list except as a convenience in filling in a text
    >> field. It's a text field, not a menu.
    >> -- In the setter method for the value property, modify the
    >> contentValues array, if desired.
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • I think I have exhausted all the options, and have come to the
    conclusion that this doesn't work. Please prove me wrong, I would love
    to have this working:

    I want to bind to NSComboBox in such a way, that the item titles
    showing in the drop down list is like this: 1-some text, 2-another
    text, 3-yet another text....
    But when I actually select one item in the list, the NSNumber for that
    item is stored in an instance variable, and not the title showed. (I f
    I select the item "2-another text" the NSNumber for 2 is to be stored).

    Can this be done? I always gets the item title stored, and I had the
    impression from Apple's documentation that this should be possible. But
    there is no example of NSComboBox bindings what I could find on this
    list, nor on the internet.

    Ivan C Myrvold
    OrtopediService AS
    Mob. 913 16 356
    Tlf. 38 14 45 93
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month december 2003 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 31        
Go to today