3
votes

i've searched for several hours, and didn't find an answer for my problem.

i'm trying to place comboboxes in a datagrid filled with DYNAMIC data. (the number and the content of these comboboxes always change. i don't know in advance how many columns there are, where i need to use comboboxes. so every single combobox gets a unique dataprovider, which comes from an external source, WHEN the program runs.)

-i found MANY threads discussing this problem, but solving via crappy mxml files, filling the comboboxes inside the sourcecode by hand. i want to point out, that isn't good for me.

-i found a better solution, in which they used some sort of custom itemrenderer to get the data from the internet. (kind of a country chooser thing) but sadly that wasn't good enough, because the number and name of the countries in the world are static more or less, they don't change. so their renderer class didn't depend on any parameters from the main algorithm.

but in my program i calculate the data in my own actionscript objects, then fill an arraylist with that. so at the beginning i load the desired data from the net, and when i get the response of the urlrequest, AFTER that i start to populate the datagrid/combobox.

i can fill any datagrid or combobox without trouble, but to put that combobox inside a datagrid cell seems to be impossible.

could anyone please help? it drives me crazy. i managed to do this in several languages before, c#, java, even php+html, but in flex it looks way too complicated then it should be.

EDIT: i'm aware, that this amount of network activity could mean some load on the server. i didn't design the philosophy behind it, i just need to wrote a client which meets the expectations. my program looks something like this:

(i'm willing to rewrite any part of it, just to make those nasty comboboxes work)

=========

main.mxml file

this is the main program, i handle some login related stuff here, and set basic design properties for the datagrids. (for example: maxwidth, maxheight, layout constraints etc.) nothing interesting, except the command when i instantiate the actionscript class, which i wrote to fill the datagrid.

"..<fx:Script>
    <![CDATA[
        private var myGrid1:MyGridType;
        ..
        somefunction {
            myGrid1 = new MyGridType(theDatagridDefinedBefore, "argumentNeededToFillDataGridsWithUniqueData");
        }
    ]]>
</fx:Script>.."

=========

MyGridType.as file

in the constructor i call a urlrequest with the help of the second argument, then add an eventlistener to it. when the data arrives, the eventlistener fires the filler function: i read the results into an arraycollection, then make it the dataprovider for the the datagrid in the first argument.

so far so good.

here comes the trouble with the comboboxes. for a specific number columns, i instantiate my combobox class. let's call that class "MyComboBoxType".

"..
blablabla = new MyComboBoxType(theDatagridDefinedBefore, param1, param2, param3);"

=========

MyComboBoxType.as file

i do nearly exactly the same, what i did in the MyGridType class. call for help from the net with param1-2-3. when i receive the data, fill an arraycollection. maybe set that arraycollection to be the dataprovider for a combobox. AAAAAAAND now i want that arraycollection or combobox to be on the datagrid "theDatagridDefinedBefore".

2
Maybe you should provide some sample code or something. It sounds to me like number 2 is your answer. The whole thing sounds like a performance nightmare, though.JeffryHouser
thanks for dropping by! i've added some details, hopefully it helps.Adam

2 Answers

0
votes

I know it's not exactly what you're trying to accomplish, but I had a somewhat similar issue in the past. Take a look at How to get the value of a ComboBox within a DataGrid to see if it helps.

If it were me, I would populate the entire ArrayCollection set before binding them to the datagrid if at all possible.

0
votes

You should build up your custom [Bindable] data structure - say MyGridData class - for the rows in the grid (if you haven't done it yet);

  • the dataProvider of your grid should be an Array / ArrayCollection /.. of MyGridData objects.
  • this step clearly works already, but for the integrity: override the getItemEditor function, or specify it explicitly using mxml, to return the combobox when needed.
  • as for the dataProvider of the combobox, you should specify the data.comboArray from inside the renderer class, where data is the MyGridData instance used by the row you are processing. (overriding the set data(value: Object):void function, you can pre-process it.)
  • this way, you are working with the reference of your original instances, and by the binding you can detect / show any changes to them directly.