Accessing Data of a ComboBox with an ArrayCollection dataProvider

[Bindable]
public var groupsList:ArrayCollection;

public function groupListRH(event:ResultEvent):void
{ 
     groupsList=event.result as ArrayCollection;       
}

<mx:ComboBox dataProvider="{groupsList}" 
             labelField="groupName"
             id="grpLst"  width="150"
             prompt="Select one group "                                   
             close="selectedItem=ComboBox(event.target).selectedIndex"               
             focusIn="init();" /> 

<mx:LinkButton label="New Group" id="creatgrp" click="addNewGroup();"/>

Here am getting array of groups(groupName,GroupID each row ) from a RemoteObject and displaying in a ComboBox. I am selecting the groups with selectedIndex as 0,1,2,3, but I want my groupIDs of correspoding groupnames,which am bringing to client side.

How can I get actual the groupId of the selected group?

Upvotes: 0

Views: 2609

Answers (1)

Ryan Lynch
Ryan Lynch

Reputation: 7776

You should be able to get it like so:

grpLst.selectedItem.GroupID;

EDIT

Or from within an mx.events.ListEvent.CHANGE handler attached to the ComboBox:

event.target.selectedItem.GroupID

EDIT

Ah, the code formatting has been updated and its easier to read. I see you are using the close event, and setting a variable called selectedItem to the selectedIndex property of the ComboBox. You could just change it so that the variable selectedItem actually references the selectedItem propterty of the ComboBox like so:

selectedItem=(event.target as ComboBox).selectedIndex;
// Then get the GroupID from the selectedItem
selectedGroupID = selectedItem.GroupID

Or just use the index to get the data from the dataProvider:

selectedIndex=(event.target as ComboBox).selectedIndex;
// Then get the GroupID from the dataProvider
selectedGroupID = groupList[selectedIndex]['GroupID']

Upvotes: 2

Related Questions