PDA

View Full Version : Help with DataGrid, Events and selectedItem and loose coupling


Elsa
08-10-2006, 12:45 AM
I'm pretty new to Flex, but I know this must be possible, however search as I might I can't find any examples of what I need online, so I'm hoping someone here can help me out, or point me in the right direction.

I've got two custom components, one with a DataGrid that has an ArrayCollection as it's dataprovider, and the other is a simple panel - just meant for displaying further details of whatever item is selected in the datagrid.

How can I pass the selectedItem from the DataGrid across to the panel component? At the moment I can't seem to pass it outside of the datagrid component, perhaps because I'm not using the right Event or because I'm not binding it properly.

Thanks,
Elsa

Elsa
08-10-2006, 10:24 AM
Ok I'll add some code as the lack of responses suggests that I'm not making the problem very clear.

Here is the function I'm trying to create to pass the selectedItem data up to the Application:

private function selectHandler():void
{
var event:Event = new Event("movieSelect");
event = listItems.selectedItem

//event.target.selectedItem = listItems.selectedItem;
dispatchEvent(event);
}

Tink
08-10-2006, 11:10 AM
hmm i'm really not sure what you up to here

//first you create an Event and store it in the var 'event'
var event:Event = new Event("movieSelect");

//now you try and set the var event to a integer
event = listItems.selectedItem

//now you try to dispatch the integer
dispatchEvent(event);

Elsa
08-10-2006, 01:27 PM
I'm calling the function at from the datagrid change="selectHandler()"

It seems easy enough to pass selectedItem to down a child component, but both my componenets are sat in the Application, so I need to pass the selectedItem up to the Application first.

Is selectedItem an int? I know selectedIndex is but I thought selectedItem was a Object that captures the selected item so you could refer to it, in the same way as you would the array e.g.

datagridID.selectedItem.fieldyouwant

Thanks.

Tink
08-10-2006, 01:50 PM
Is selectedItem an int? I know selectedIndex is but I thought selectedItem was a Object that captures the selected item so you could refer to it, in the same way as you would the array e.g.sorry yes its an Object, it aint and Event object though, so u can't dispatch it like that.

Can u paste all your code so we can actually see what your doing?

Elsa
08-10-2006, 05:52 PM
Peter Ent from Adobe has rescued me....

Adobe Forums (http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=585&threadid=1182156&enterthread=y)

But thanks Tink I appreciate you looking.