views:

969

answers:

2

Hello Everyone,

Within a DataGrid, I have a DataGridColumn that uses a custom component as the item renderer. Within the component, I have an ArrayCollection that stores a set of value objects. My problem is that I cannot access the ArrayCollection values from outside of the item renderer component. Does anyone know how it would be possible to do this? I have posted a code snippet below.

<mx:Script>
    <![CDATA[
        // Cannot access arrFiles from here.
    ]]>
</mx:Script>
<mx:DataGrid editable="true">
    <mx:columns>
        <mx:DataGridColumn id="dgcUpload" width="130" headerText="Uploaded Files"
        editable="false">
        <mx:itemRenderer>
     <mx:Component>
                    <mx:VBox>
                        <mx:Script>
                            <![CDATA[
                                [Bindable]public var arrFiles:ArrayCollection = new ArrayCollection();
                            ]]>
                        </mx:Script>
                    </mx:VBox>
     </mx:Component>
        </mx:itemRenderer>
        </mx:DataGridColumn>
    </mx:columns>
</mx:DataGrid>

Is this possible?

Thank you in advance for any assistance,

Orville

+1  A: 

It is possible depending on how you want to access it. You can access the property of a specific item being rendered by the itemRenderer by calling the itemToItemRenderer function on the datagrid. That gives you an instance of that specific itemRenderer and you can call the arrFiles variable for that item.

Here's an example

  protected function datagrid1_clickHandler(event:MouseEvent):void
  {
   var obj:Object = dgcUpload.itemToItemRenderer(dgcUpload.selectedItem);
   var newArray:ArrayCollection = obj.arrFiles;
  }

I call that when something is clicked on the DataGrid and I want to access the arrFiles variable for the selected item.

Is that what you're looking for?

=Ryan

ryanstewart
That sort of helps Ryan. What I am trying to do is iterate over the DataGrid and add each array of files its corresponding row in a shopping cart array.
Would this be something you could just do with an Array of Array's as the dataProvider?
ryanstewart
Unless something is changing that you can detect in select events, just use the original dataprovider. Like Ryan said.
Glenn
I have worked with Flex for a long time but, up until now, have mostly used the DataGrid for formatted data display so working with inline components is new to me. I originally set up the file upload column to store an array of filenames but never did figure out how to bind that array to the DataGrid dataprovider. So what I did to solve the problem was convert the array to a string of filenames each separated by a forward slash.Thank you all for helping! Ryan, I added your blog to my RSS feed reader.
A: 

I would create a custom MXML Box component as the rendered with a label (myLabel) as a child. Set the data provider for the DataGrid to the array. In the custom MXML component override the set data method which is called each time the data is rendered for each row and set the label to the current value passed in:

override public function set data(value:Object):void{
         myLabel.text = value.myTextForLabel;
}

If the field in the ArrayCollection (myArrayCollection) is always the same for the label, then just set the DataGrid data provider to the ArrayCollection and the dataField property of the column to the appropriate value (myText):

<mx:DataGrid editable="true" dataProvider="myArrayCollection">
   <mx:columns>
    <mx:DataGridColumn id="dgcUpload" width="130" dataField="myText" headerText="Uploaded Files"
    editable="false">
   </mx:columns>
</mx:DataGrid>
Jeff Pinkston