12 Replies Latest reply on Nov 19, 2008 2:28 PM by Newsgroup_User

    Tough question: combobox in datagrid with different options on every row

    happybrowndog
      Hello,

      I need to put a combobox in a column on a datagrid, but each row may have different values to select from in the combobox.

      My application has a datagrid that sits on a panel with a button to add a row to the datagrid. The button opens a popup dialog asking what kind of data will be on the new row. The new row is appended as XML in the datagrid's dataprovider, so that the new row appears in the datagrid as per the Flex way. However, one column has a combobox, but this combobox needs to show different selectable values that depend on the kind of row the user determined in the popup dialog.

      How can the problem of the combobox be achieved? I looked into perhaps having a different data provider for each combobox, but I don't see how to achieve that because of the way objects are instantiated via a class factory for a datagrid. I also thought about somehow having one dataprovider for all the comboboxes, but only showing a subset of values for selection depending on the row it is on, but I don't know how to do that - even when the source for the dataprovider is xml and having some kind of attribute in the xml tag that would help the combobox decide whether to show it or not. Still, I don't know how one would implement that either. I suppose some creative solution is required.....

      Does anybody have any ideas of how I can achieve this please?
        • 1. Re: Tough question: combobox in datagrid with different options on every row
          Level 7

          "happybrowndog" <webforumsuser@macromedia.com> wrote in message
          news:gg04is$9p7$1@forums.macromedia.com...
          > Hello,
          >
          > I need to put a combobox in a column on a datagrid, but each row may have
          > different values to select from in the combobox.
          >
          > My application has a datagrid that sits on a panel with a button to add a
          > row
          > to the datagrid. The button opens a popup dialog asking what kind of data
          > will
          > be on the new row. The new row is appended as XML in the datagrid's
          > dataprovider, so that the new row appears in the datagrid as per the Flex
          > way.
          > However, one column has a combobox, but this combobox needs to show
          > different
          > selectable values that depend on the kind of row the user determined in
          > the
          > popup dialog.
          >
          > How can the problem of the combobox be achieved? I looked into perhaps
          > having
          > a different data provider for each combobox, but I don't see how to
          > achieve
          > that because of the way objects are instantiated via a class factory for a
          > datagrid. I also thought about somehow having one dataprovider for all
          > the
          > comboboxes, but only showing a subset of values for selection depending on
          > the
          > row it is on, but I don't know how to do that - even when the source for
          > the
          > dataprovider is xml and having some kind of attribute in the xml tag that
          > would
          > help the combobox decide whether to show it or not. Still, I don't know
          > how
          > one would implement that either. I suppose some creative solution is
          > required.....
          >
          > Does anybody have any ideas of how I can achieve this please?

          http://www.cflex.net/showFileDetails.cfm?ObjectID=767


          • 2. Re: Tough question: combobox in datagrid with different options on every row
            happybrowndog Level 1
            Thanks for that Amy.
            I compiled your code and ran it through the debugger, and it works.
            I also went through your code and looked up the references in the flex documentation, and I am a bit puzzled.... in your subclassed combobox ("ComboBoxSelectedValue") you have a set method on "selectedValue" and a note above it that it is "...Set by the parent, often by an ItemRenderer wrapper".

            I looked all over the place in the flex docs, including the ItemRenderer interfaces, ComboBox, ComboBase, up and down inheritance trees and sideways through the implements, but can't find where objects would call that. It's not even an override of a ComboBox or one of its parent classes! On the web I can't even find a reference to it. Can you please explain in a little more detail how it fits in?

            I suppose that the same thing also goes for the set method on "dropDownDataField"?

            Thanks.
            • 3. Re: Tough question: combobox in datagrid with different options on every row
              Level 7

              "happybrowndog" <webforumsuser@macromedia.com> wrote in message
              news:gg0qhl$9ae$1@forums.macromedia.com...
              > Thanks for that Amy.
              > I compiled your code and ran it through the debugger, and it works.
              > I also went through your code and looked up the references in the flex
              > documentation, and I am a bit puzzled.... in your subclassed combobox
              > ("ComboBoxSelectedValue") you have a set method on "selectedValue" and a
              > note
              > above it that it is "...Set by the parent, often by an ItemRenderer
              > wrapper".
              >
              > I looked all over the place in the flex docs, including the ItemRenderer
              > interfaces, ComboBox, ComboBase, up and down inheritance trees and
              > sideways
              > through the implements, but can't find where objects would call that.
              > It's not
              > even an override of a ComboBox or one of its parent classes! On the web I
              > can't even find a reference to it. Can you please explain in a little
              > more
              > detail how it fits in?
              >
              > I suppose that the same thing also goes for the set method on
              > "dropDownDataField"?

              Not my example, so if this is inaccurate please excuse. A set method is a
              way to expose a public property (plus add some additional functionality).
              If you don't see the word "override" in that method statement, then that is
              a new public property that has been invented specifically for that
              component. To call a set method, you do something like this:

              customComponent.selectedValue='foo';

              Then Flex passes in 'foo' as the argument for the function, and whatever
              other processing specified in the function definition will happen.

              HTH;

              Amy


              • 4. Re: Tough question: combobox in datagrid with different options on every row
                happybrowndog Level 1
                Yes thank you, but my question was not that simple. In the code that you gave the link to, no call to the property selectedValue of the class ComboBoxSelectedValue is made. So is the code made somehow because ComboBox extends itemRenderer (or some derivative) and because it sits in the datagrid, the container of ComboBox calls it?
                • 5. Re: Tough question: combobox in datagrid with different options on every row
                  Gregory Lafrance Level 6
                  This code in DGIR_DynamicDP.mxml "sets" the value of selectedValue:

                  this.selectedValue = _oItem[_sDataField];

                  When this is called the "set" method for selectedValue is called. This is something unique to Flex (and maybe some other languages but this is the first time I've seen it).

                  Are you familiar with how "getters" and "setters" work in Flex? If not the FB help or LiveDocs will give a good overview.
                  • 6. Re: Tough question: combobox in datagrid with different options on every row
                    Level 7

                    "Greg Lafrance" <webforumsuser@macromedia.com> wrote in message
                    news:gg1i1o$9u6$1@forums.macromedia.com...
                    > This code in DGIR_DynamicDP.mxml "sets" the value of selectedValue:
                    >
                    > this.selectedValue = _oItem[_sDataField];
                    >
                    > When this is called the "set" method for selectedValue is called. This is
                    > something unique to Flex (and maybe some other languages but this is the
                    > first
                    > time I've seen it).
                    >
                    > Are you familiar with how "getters" and "setters" work in Flex? If not the
                    > FB
                    > help or LiveDocs will give a good overview.

                    Yes, that's essentially what I said, except Greg's not too lazy to go look
                    into the example code.


                    • 7. Re: Tough question: combobox in datagrid with different options on every row
                      happybrowndog Level 1
                      I saw that code there already, but - here is the setter and the comment above it:

                      /** Set by the parent, often by an ItemRenderer wrapper. */
                      public function set selectedValue(o:Object):void
                      { ...

                      So because of the comment, I expected that something outside of the class ComboBoxSelectedValue would be setting that property. In fact, DGIR_DynamicDP subclasses ComboBoxSelectedValue, so why would it need to access it as a public property (could it not have been an inherited variable)? That the setter is public is another reason I was looking outside ComboBoxSelectedValue, not in one of its subclasses. I still ask though, is it possibly being set from outside because ComboBox implements some interface?

                      By the way, "getter" and "setter" exist in C# and Java. AS seems to be closer to Java than C#. And Flex seems to be a better Swing (which was stunningly horrible).
                      • 8. Re: Tough question: combobox in datagrid with different options on every row
                        Gregory Lafrance Level 6
                        Hmmm... I wonder if that comment above the setter was erroneous, as the variable seems to be set elsewhere.

                        Thanks for the insight into getters and setters in C# and Java. It's good to hear Flex has advantages over Swing.

                        I'm hoping Flex/AIR will be the next Java (and hopefully even better). If so, mastering it now will lead to more cash. What do you think about the future of Flex/AIR?
                        • 9. Re: Tough question: combobox in datagrid with different options on every row
                          happybrowndog Level 1
                          So I took the code in ComboBoxSelectedValue.mxml and changed:
                          public function set selectedValue(o:Object):void
                          to:
                          internal function set selectedValue(o:Object):void
                          and ran it through FB, and it ran without errors.

                          PROVIDED there is not an issue that might occur because the datagrid "instantiates" from the class factory instances of grid child objects as they need to be rendered, that would make some call to itemRenderer methods, I'd make the assumption that the code was in error needlessly setting it to public to begin with.

                          However, the comment in the code just above the setter method:
                          /** Set by the parent, often by an ItemRenderer wrapper. */
                          leads me to think that my provisory may hold true after all - making my assumption wrong.

                          So someone PLEASE tell me if the setter should be public and why?
                          • 10. Re: Tough question: combobox in datagrid with different options on every row
                            Level 7

                            "happybrowndog" <webforumsuser@macromedia.com> wrote in message
                            news:gg1o2i$ht8$1@forums.macromedia.com...
                            > So I took the code in ComboBoxSelectedValue.mxml and changed:
                            > public function set selectedValue(o:Object):void
                            > to:
                            > internal function set selectedValue(o:Object):void
                            > and ran it through FB, and it ran without errors.
                            >
                            > PROVIDED there is not an issue that might occur because the datagrid
                            > "instantiates" from the class factory instances of grid child objects as
                            > they
                            > need to be rendered, that would make some call to itemRenderer methods,
                            > I'd
                            > make the assumption that the code was in error needlessly setting it to
                            > public
                            > to begin with.
                            >
                            > However, the comment in the code just above the setter method:
                            > /** Set by the parent, often by an ItemRenderer wrapper. */
                            > leads me to think that my provisory may hold true after all - making my
                            > assumption wrong.
                            >
                            > So someone PLEASE tell me if the setter should be public and why?

                            If it doesn't say "override" in it, and clearly it doesn't, or you couldn't
                            have changed it to (surely you meant "protected"?) internal, then OF COURSE
                            the dataGrid doesn't know anything about the property, because it's not an
                            existing property on any object that ever existed when the Framework was
                            released. Thought I'd made that clear?

                            However, you might want to create a ClassFactory yourself that sets that
                            property. If you do, you might want to leave it public.


                            • 11. Re: Tough question: combobox in datagrid with different options on every row
                              happybrowndog Level 1
                              quote:



                              If it doesn't say "override" in it, and clearly it doesn't, or you couldn't
                              have changed it to (surely you meant "protected"?) internal, then OF COURSE
                              the dataGrid doesn't know anything about the property, because it's not an
                              existing property on any object that ever existed when the Framework was
                              released. Thought I'd made that clear?

                              However, you might want to create a ClassFactory yourself that sets that
                              property. If you do, you might want to leave it public.





                              Your last statement about setting it after creation through a ClassFactory is getting somewhere to addressing the problem, sort of.

                              Please inspect the code, I suspect you have not. The method in question is the public setter for selectedValue, which when I run through the debugger shows that it gets called when the user selects a value in the combobox. It implies that either the datagrid or the datagrid column, or whatever is actually containing the combobox is calling that method. But nowhere in the inheritance tree for ComboBox can I find that it is a property defined for public access (or as you say, would have an "override"). But that is my point as well - which is only a basic fact you restated again. So then how is this setter getting called? Does the comment given in the code not imply to you that it is somehow being accessed from outside the object (and not merely in the subclass)?

                              • 12. Re: Tough question: combobox in datagrid with different options on every row
                                Level 7

                                "happybrowndog" <webforumsuser@macromedia.com> wrote in message
                                news:gg1vrb$ruo$1@forums.macromedia.com...
                                >
                                quote:


                                >
                                > If it doesn't say "override" in it, and clearly it doesn't, or you
                                > couldn't
                                > have changed it to (surely you meant "protected"?) internal, then OF
                                > COURSE
                                > the dataGrid doesn't know anything about the property, because it's not an
                                > existing property on any object that ever existed when the Framework was
                                > released. Thought I'd made that clear?
                                >
                                > However, you might want to create a ClassFactory yourself that sets that
                                > property. If you do, you might want to leave it public.
                                >
                                >
                                >

                                >
                                > Your last statement about setting it after creation through a ClassFactory
                                > is
                                > getting somewhere to addressing the problem, sort of.

                                I think you didn't understand what I said. You'd use ClassFactory to set
                                the variable _before_ creation.

                                > Please inspect the code, I suspect you have not.

                                No, and I'm not gonna. It's not my fault you're not "getting" what I'm
                                saying. There are certain things that are just true, and I don't need to
                                look at a particular instance of code to know that they are. One of those
                                things is that if there was not a component in the original Flex Framework
                                that had a particular property that a new, custom component had, of COURSE
                                the framework cannot address it.

                                > The method in question is
                                > the public setter for selectedValue, which when I run through the debugger
                                > shows that it gets called when the user selects a value in the combobox.

                                Yes, Tracy probably override the setter that gets called when a selection is
                                made and sets selectedValue there, just as the override for set data is what
                                sets the selection from the datagrid or whatever is consuming this as a
                                renderer.

                                > It
                                > implies that either the datagrid or the datagrid column, or whatever is
                                > actually containing the combobox is calling that method.

                                Clearly not, if it is being selected via user interaction--the datagrid is
                                not involved until after the selection changes.

                                > But nowhere in the
                                > inheritance tree for ComboBox can I find that it is a property defined for
                                > public access (or as you say, would have an "override"). But that is my
                                > point
                                > as well - which is only a basic fact you restated again. So then how is
                                > this
                                > setter getting called? Does the comment given in the code not imply to
                                > you
                                > that it is somehow being accessed from outside the object (and not merely
                                > in
                                > the subclass)?

                                No, it implies that someone put as much effort as they thought was useful to
                                _them_ when creating the example, and even in the actual Flex docs that
                                someone got paid fairly good money to write, there are all sorts of
                                inaccurate or misleading statements.

                                If you start a new thread and append ATTN: Tracy Spratt to the subject line,
                                he might be nice and tell you what was going through his head at the moment
                                he wrote that comment, if he remembers.