DataGrid Combobox dataprovider erasing items

I have a DataGrid that is linked to an array of custom data objects which I call a seriesList.  You are supposed to be able to choose the name of each series via a combobox in the datagrid.  It works fine except when the user selects the combobox and then clicks somewhere else in the interface, which closes the combobox and erases whichever item is previously selected!
<!--  Definition in application  -->
<!--  axis.seriesList is and ArrayCollection of actionscript objects called SeriesObjects which have a var name:String variable -->
<mx:DataGrid id="seriesTable" color="black" fontSize="9" rowHeight="30" editable="true" resizeEffect="slow" rollOverColor="#CCCCCC"
    selectionColor="#999999" dataProvider="{axis.seriesList}" width="100%"
    rowCount="{axis.seriesList.length > 2 ? axis.seriesList.length : 2}" >
        <mx:columns>  
             <mx:DataGridColumn dataField="name" headerText="Name" width="280" headerStyleName="centered" id="nameColumn"
                     rendererIsEditor="true"  editorDataField="result" itemRenderer="renderer.SeriesBoxRenderer"/>
        </mx:columns>
</mx:DataGrid>
<!--  SeriesBoxRenderer -->
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" horizontalAlign="center">
   <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            // Define a property for returning the new value to the cell.
            public var result:String="";
            [Bindable]
            private var dpValue:ArrayCollection;
            private function init():void {
                // list of possible names to choose from for this series
                dpValue = mx.core.Application.application.seriesArray;
            // Override the set method for the data property.
            override public function set data(value:Object):void {
                if (dpValue == null) init();
                super.data = value;
                if (value != null)     {
                    var currentValue:String = value.name;
                    var len:int = dpValue.length;
                    for (var i:int = 0; i < len; i++) {
                        if (dpValue[i].name == currentValue) {
                            editor.selectedIndex = i;
                            return;
                editor.selectedIndex = 0;            }
            public function onChange():void {
                var index:int = editor.selectedIndex;
                result = dpValue[index].name;
                data.name = dpValue[index].name;
        ]]>
    </mx:Script>
     <mx:ComboBox id="editor" textAlign="left" labelField="name" dataProvider="{dpValue}"  change="onChange()"/>
</mx:VBox>

I'm thinking the problem may be the dataprovider for the combobox.  This array is also shared with another List component in another tab on the interface.  The reason I am thinking this is because I have another item renderer which uses a combobox and does not erase itself when you click nothing.  Here is the code for that item, and the only difference I can see between this code and the code that doesn't work is the fact that the dataprovider is shared with another part of the code.  Still not sure how to fix this, however.
          [Bindable]
            private var dpValue:ArrayCollection;
            private function init():void {
                dpValue = mx.core.Application.application.aquisitionOptions.lastResult.system.data;
                for ( var i:int=0; i<dpValue.length; i++ )  {  //loop over the items in the dataProvider
                   if (dpValue[i].id == data.aquisitionID)  {  //compare desired value to current item.data value
                        editor.selectedIndex = i;  //set the seletedIndex of the combo box
                        data.aquisitionDescr = dpValue[i].name;
                        break;
          // Override the set method for the data property.
            override public function set data(value:Object):void {
                super.data = value;
                if (dpValue == null) init();
                if (value != null)     {        
                    var currentValue:String = value.aquisitionDescr;
                    trace ("\n current:  ", currentValue);
                    var len:int = dpValue.length;
                    for (var i:int = 0; i < len; i++) {
                        if (dpValue[i].name == currentValue) {
                            editor.selectedIndex = i;
                            return;
                editor.selectedIndex = 0;
            public function onChange():void {
                var index:int = editor.selectedIndex;
                result = dpValue[index].name;
                data.aquisitionDescr = dpValue[index].name;
                data.aquisitionID = editor.selectedItem.id as String;
        ]]>
    </mx:Script>
     <mx:ComboBox id="editor" labelField="name" dataProvider="{dpValue}" change="onChange()"/>
<!-- definition in the datagrid -->
<mx:DataGridColumn dataField="aquisitionDescr" headerText="Data Aquisition" width="160" headerStyleName="centered" id="acquisitionColumn"
                     rendererIsEditor="true"  editorDataField="result" itemRenderer="renderer.AquisitionBoxRenderer"/>

Similar Messages

  • Dynamic dataprovider in Datagrid combobox.

    Hi,
    i am using Flex 3. I have a data grid with first two rows having item renderers as ComboBoxes. What i want to implement is that, depending on my selection in the first combobox, the respective second combobox should get a dataprovider of my choice.
    For e.g.
    If I select the 1st combobox as India, then the adjacent combobox should have the cities in India.
    If I select the 1st combobox as France, then the adjacent combobox should have the cities in France.
    I dont have the values in any local variables. The values must be fetched at runtime because the list of Countries(in first combobox) is very exaustive so fetching the list of all cities for all countries would not be right. So for each selection of country i have to make an http service call to fetch the corresponding city list.
    My question is how do i dynamically give the cities as dataprovider to each of the combo boxes in each row.
    Hope my description is comprehensible enough.
    Thanks
    Sid.

    HI,
    Can you check the below code. If that is what you need.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                     layout="vertical"
                     creationComplete="application1_initializeHandler(event)">
         <mx:Script>
             <![CDATA[
                 import mx.collections.ArrayCollection;
                 import mx.events.FlexEvent;
                 // Defines your collections
                 [Bindable]
                 public var countriesData:ArrayCollection=new ArrayCollection([{label: 'India'}, {label: 'Brazil'}]);
                 [Bindable]
                 public var citiesData:ArrayCollection;
                 [Bindable]
                 public var collection:ArrayCollection=new ArrayCollection();
                 protected function application1_initializeHandler(event:FlexEvent):void
                     dataGrid.addEventListener("countryChanged", country_changed_handler);
                     collection.addItem({cityData:citiesData});
                // Change this method to the remote callings.
                // In the resultEvent you will change the citiesData collection.
                 protected function country_changed_handler(event:DataEvent):void
                     if (event.data == 'India')
                         dataGrid.selectedItem.cityData = new ArrayCollection([{label: 'Mumbai'}, {label: 'Delhi'}]);
                     else
                         dataGrid.selectedItem.cityData = new ArrayCollection([{label: 'São Paulo'}, {label: 'Rio de Janeiro'}]);
                     dataGrid.invalidateList();
                 public function addRow(event:MouseEvent):void{
                     //collection.addItem(new Object());
                     collection.addItem({cityData:citiesData});
                 public function dropRow(event:MouseEvent):void{
             ]]>
         </mx:Script>
         <mx:DataGrid id="dataGrid"
                      dataProvider="{collection}">
             <mx:columns>
                 <mx:DataGridColumn>
                     <mx:itemRenderer>
                         <mx:Component>
                             <mx:ComboBox dataProvider="{this.parentDocument.countriesData}"
                                          labelField="label"
                                          change="combobox1_changeHandler(event)"
                                          selectedIndex="-1">
                                 <mx:Script>
                                     <![CDATA[
                                         import mx.collections.ArrayCollection;
                                         import mx.events.ListEvent;
                                        protected function combobox1_changeHandler(event:ListEvent):void
                                             dispatchEvent(new DataEvent("countryChanged", true, true, this.selectedLabel));
                                     ]]>
                                 </mx:Script>
                             </mx:ComboBox>
                         </mx:Component>
                     </mx:itemRenderer>
                 </mx:DataGridColumn>
                 <mx:DataGridColumn>
                     <mx:itemRenderer>
                         <mx:Component>
                             <mx:ComboBox labelField="label">
                                 <mx:Script>
                                     <![CDATA[
                                              override public function set data(value:Object):void
                                                super.data = value;
                                                var prevSelectedItem:Object = this.selectedItem;
                                                this.dataProvider = data.cityData ;
                                                this.selectedItem = prevSelectedItem;
                                     ]]>
                                 </mx:Script>
                             </mx:ComboBox>
                         </mx:Component>
                     </mx:itemRenderer>
                 </mx:DataGridColumn>
             </mx:columns>
         </mx:DataGrid>
         <mx:HBox width="299" horizontalAlign="center" horizontalGap="51">
             <mx:Button label="Add" click="addRow(event)"/>
             <mx:Button label="Drop" click="dropRow(event)"/>
         </mx:HBox>
    </mx:Application>

  • (URGENT) Skining problem of components (datagrid & combobox)

    Hi,
    I m using FLASH CS3, I used Datagrid and Combobox component from components panel, and simply add some data inside in that.
    setupComboBox();
    function setupComboBox():void
        cb.setSize(200, 22);
        cb.prompt = "Select a Credit Card";
        cb.addItem( { label: "MasterCard", data:1 } );
        cb.addItem( { label: "Visa", data:2 } );
        cb.addItem( { label: "American Express", data:3 } );
    import fl.controls.DataGrid;
    import fl.controls.dataGridClasses.DataGridColumn;
    import fl.data.DataProvider;
    import fl.events.DataGridEvent
    var dp:DataProvider = new DataProvider();
    dp.addItem({col1:"item 1.A", col2:"item 1.B", col3:"item 1.C"});
    dp.addItem({col1:"item 2.A", col2:"item 2.B", col3:"item 2.C"});
    dp.addItem({col1:"item 3.A", col2:"item 3.B", col3:"item 3.C"});
    dp.addItem({col1:"item 4.A", col2:"item 4.B", col3:"item 4.C"});
    myDataGrid.addColumn("col1");
    myDataGrid.addColumn("col2");
    myDataGrid.addColumn("col3");
    myDataGrid.dataProvider = dp;
    myDataGrid.setSize(300, 200);
    myDataGrid.move(10, 10);
    It seems working fine.
    My problem is , I want two different type of skining of two different component(DataGrid & Combobox). in the same fla.
    .. e.g if datagrid have gray color skin type and combobox have black color skin type.
    Can any one have any Idea?

    Thanks for reply..
    @kennethkawamoto2
    I already implemented that thing , that u suggest, The Main problem of this component is CellRenderer,  what's the solution of it ?
    If i apply this
    cb.setStyle("upSkin", ComboBox_upSkin2);
    cb.setStyle("overSkin", ComboBox_overSkin2);
    cb.setStyle("downSkin", ComboBox_downSkin2);
    Its change the header of Comobo box pattern, but the rest part e.g cell  is remaining  the same.
    I  tried like this also
    cb.setStyle("upSkin",CellRenderer_upSkin2)
    cb.setStyle("downSkin",CellRenderer_downSkin2)
    cb.setStyle("overSkin",CellRenderer_overSkin2)
    cb.setStyle("disabledSkin",CellRenderer_disabledSkin2)
    cb.setStyle("selectedDisabledSkin",CellRenderer_selectedDisabledSkin2)
    cb.setStyle("selectedUpSkin",CellRenderer_selectedUpSkin2)
    cb.setStyle("selectedDownSkin",CellRenderer_selectedDownSkin2)
    cb.setStyle("selectedOverSkin",CellRenderer_selectedOverSkin2)
    but it gives error........
    TypeError: Error #2007: Parameter child must be non-null.
        at flash.display::DisplayObjectContainer/addChildAt()
        at fl.controls::BaseButton/drawBackground()
        at fl.controls::LabelButton/draw()
        at fl.core::UIComponent/drawNow()
        at fl.controls::List/drawList()
        at fl.controls::List/draw()
        at fl.core::UIComponent/drawNow()
        at fl.controls::List/scrollToIndex()
        at fl.controls::SelectableList/scrollToSelected()
        at fl.controls::ComboBox/open()
        at fl.controls::ComboBox/onToggleListVisibility()
    When u click on combobox to open it up. The Component Assets  of datagrid and combobox are the same so I am not able to apply different skin pattern of this two different component ..
    Still is there any way pls let me ..

  • I just got a WD My Passport 1TB External Harddrive and i have already backed everything up to it but im still a little nervous about erasing things off the physical drive since it says my disk utility is out of space an implying i need to erase items.

    I just got a WD My Passport 1TB External Harddrive and i have already backed everything up to it but im still a little nervous about erasing things off the physical drive on my macbook pro since it says my disk utility is out of space an implying i need to erase items.
    I cant find the options to erase selected items it only shows that i can erase everything.
    I mean technically i suppose i could erase everything an have a fresh start since its backed up to my external. But what exactly are the specific items being erased?
    I have bought the newest OS X 10.8.2 an worried that it will get erased also an end up having to repurchase it.
    Can anyone help me?
    <Personal Information Edited by Host>

    Black_Chevy07 wrote:
    I just got a WD My Passport 1TB External Harddrive and i have already backed everything up to it but im still a little nervous about erasing things off the physical drive on my macbook pro since it says my disk utility is out of space an implying i need to erase items.
    I cant find the options to erase selected items it only shows that i can erase everything.
    I mean technically i suppose i could erase everything an have a fresh start since its backed up to my external. But what exactly are the specific items being erased?
    I have bought the newest OS X 10.8.2 an worried that it will get erased also an end up having to repurchase it.
    Can anyone help me?
    If you are trying to delete some files get out of Disk Utility, it is not for that!
    How did you backup and what are you trying to achieve?
    Please post the exact error messages(s) you have received.

  • Update ComboBox model / change items

    Hi, ive hit a wall here can someone give me a leg up?
    I have two JComboBoxes
    I want selections in the first to change the items in the second.
    i.e
    I want to register the firsts ItemListener to change the seconds ComboBoxModel
    im trying to use
    myCombo2.setModel( X )
    is there anyway to convert an String[] to a ComboBoxModel so i can fit it in X?
    I origionally drew my ComboBoxes by passing String[] arrays to the constructors.
    If i make a new ComboBox when the items change i have to re add it to the panel and draw the whole frame again, is that right?
    thanks all
    :)

    Thanks for the guidance!
    It seems understanding the API docs is really usefull... DUH
    well im getting better
    in the end i solved this by
    class whatever(){
    private DefaultComboBoxModel model;
    private void createProdTypeCombo()
    model = new DefaultComboBoxModel();
    prodTypeCombo.setModel(model);
    private void createProductCombo()
    productCombo = new JComboBox((events.doQuery(
         "SELECT item FROM Products Group By item ", 1)).toArray(new String[0]));
    productCombo.addActionListener(
    new ActionListener()
    @Override
         public void actionPerformed(ActionEvent e) {
         //updates the model for the second combo box
         prodTypeCombo.removeAllItems();
         ArrayList<String> results = new ArrayList<String>();
         String selectedItem = (String)productCombo.getSelectedItem();
         results = events.doQuery("SELECT type FROM Products where " +
              "item= '" + selectedItem + "' group by type", 1);
         Object[] resultsOK = results.toArray();
         or (int i=0; i<results.size(); i++ )
              model.addElement(resultsOK);
    Thanks all!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • ComboBox without first item

    I have a Combobox with 4 items. When it�s closed
    you can see the item with index 0. If I open the
    ComboBox, I want to see all elements except thatone
    with index 0. This should only be seen in the normal
    closed Combobox field and not in the opened, too.
    Has someone a model or a renderer
    for that problem. It�s very urgent.
    Thanx and regards
    Stephan

    I tried it, after des FocusGained Event,
    but it doesn�t work that way:
    private void jComboBox1FocusGained(java.awt.event.FocusEvent evt) {
    jComboBox1.setSelectedItem(null);
    regards
    Stephan

  • DataGrid ComboBox itemRenderer/editor not updating dataProvider properly

    I have a DataGrid with one column using a ComboBox as the itemRenderer. The column is editable but if you trace the dataProvider, the changes lag behind by one. So uncheck two row's ComboBox and the dataProvider only shows one row's data updated.
    Any ideas?

    Yep, its a CheckBox, too early in the morning.
    Another component (DataGrid) will be filtered depending on what rows in the ADG have their CheckBox checked, so leaving the row may be too late.
    Here is the code I have so far. In the itemEditEnd event handler I'm trying to set the field in the dataProvider manually, but it causes an infinite loop. preventDefault and stopImmediatePropagation don't help.
    ----- CheckBoxRenderer.mxml -----
    <?xml version="1.0"?>
    <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
      <mx:Script>
        <![CDATA[
          import mx.controls.CheckBox;
          [Bindable] public var newSelected:Boolean;
        ]]>
      </mx:Script>
      <mx:CheckBox id="selectedChbx" selected="{data.FLAG}"/>
    </mx:VBox>
    ----- mainapp.mxml -----
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
      <mx:Script>
        <![CDATA[
          import mx.events.AdvancedDataGridEvent;
          import mx.collections.ArrayCollection;
          import mx.controls.CheckBox;
          [Bindable] private var transactions:ArrayCollection = new ArrayCollection([
            {orderID: "33725", theirOrderNumber: "10170", name: "Bob Smith", SKUs: "21", PICKS: "50", FLAG: "true"},
            {orderID: "33729", theirOrderNumber: "10172", name: "Mary Wilson", SKUs: "3", PICKS: "6", FLAG: "true"},
            {orderID: "33730", theirOrderNumber: "10176", name: "Fred Carson", SKUs: "1", PICKS: "2", FLAG: "true"},
            {orderID: "33731", theirOrderNumber: "10177", name: "Morten Hills", SKUs: "5", PICKS: "16", FLAG: "true"},
            {orderID: "33732", theirOrderNumber: "10178", name: "Bill Trundy", SKUs: "5", PICKS: "34", FLAG: "true"},
            {orderID: "33734", theirOrderNumber: "10179", name: "Ocean Boat Supply", SKUs: "8", PICKS: "19", FLAG: "true"},
            {orderID: "33736", theirOrderNumber: "10180", name: "Janet Aberdine", SKUs: "5", PICKS: "18", FLAG: "true"},
            {orderID: "33737", theirOrderNumber: "10181", name: "Kim Restine", SKUs: "2", PICKS: "6", FLAG: "true"},
            {orderID: "33738", theirOrderNumber: "10182", name: "Thomas Overby", SKUs: "5", PICKS: "12", FLAG: "true"}
          public function handleGridChanged(evt:AdvancedDataGridEvent):void{
            var newData:Boolean = CheckBoxRenderer(evt.currentTarget.itemEditorInstance).newSelected;
            trace(evt.rowIndex);
            var obj:Object = transactions.getItemAt(evt.rowIndex);
            trace("BEFORE: " + obj.FLAG);
            obj.FLAG = newData;
            trace("AFTER: " + obj.FLAG);
            transactions.setItemAt(obj, evt.rowIndex);
            return;
            evt.preventDefault();
            evt.stopImmediatePropagation();
    //        for each(var item:Object in transactions){
              //trace(item.FLAG);
        ]]>
      </mx:Script>
      <mx:Label fontSize="12" text="Bulk Print / Pull - Step 1"/>
      <mx:HBox>
        <mx:AdvancedDataGrid id="dgTransactions" dataProvider="{transactions}"
          fontSize="12" editable="true" sortableColumns="true" height="500"
          width="100%" itemEditEnd="handleGridChanged(event);">
            <mx:columns>
              <mx:AdvancedDataGridColumn dataField="orderID" headerText="WMSOID" width="100"
                editable="false" textAlign="center"/>
              <mx:AdvancedDataGridColumn dataField="theirOrderNumber" headerText="Order #"
                textAlign="center" width="130" editable="false"/>
              <mx:AdvancedDataGridColumn dataField="name" headerText="Customer"
                width="125" textAlign="left" editable="false"/>
              <mx:AdvancedDataGridColumn dataField="SKUs" headerText="SKU's"
                width="75" textAlign="right" editable="false"/>
              <mx:AdvancedDataGridColumn dataField="PICKS" headerText="Picks"
                width="75" textAlign="right" editable="false"/>    
              <mx:AdvancedDataGridColumn dataField="FLAG" headerText="I" width="20" textAlign="center"
                editable="true" rendererIsEditor="true" editorDataField="newSelected"
                itemRenderer="CheckBoxRenderer"/>
            </mx:columns>
        </mx:AdvancedDataGrid>
        <mx:DataGrid>
        </mx:DataGrid>
      </mx:HBox>
    </mx:Application>

  • Datagrid combobox as itemrenderer problem.

    Hi All,
         I have different problem. i have a datagrid with10-20 rows. Different item renderers in all columns(6 - 10 columns). In that a single column has combobox as item rederer.
         I have to serve different dataprovider for each row's combobox. I assigned dataprovider by overriding data property. is this right?.
         while my datagrid has scrollbar frequently my rows are refreshing. This makes bad my app.
         Please help me.

    Yes, what you are doing is right, if you think that once the data provider is set on the combobox, and it does not change(except the selected value) then do not assign the data provider from override.
    I would create a dirty flag in the combo itemrend and set this to true once the dataprovider is set on the combo, and will not set the dp again when the override data is called by looking at this dirty flag.

  • DataGrid/ComboBox/ItemEditor

    Hi all,
    I've got a DataGrid, "dg", whose dataprovider is set to an
    array of "thing" objects.
    Each row then has several columns using a custom renderer, a
    canvas containing a combobox. The combobox's dataprovider is set to
    thing's array of "subthing" objects. The editorDataField for each
    row is set to "selectedItem".
    When a combobox is changed, I need to set Thing.subthing =
    combobox.selectedItem. Unfortunately I can't make this happen.
    If I don't include a "selectedItem" variable within the MXML
    component definition, I get the following RTE on focus out of the
    combobox:
    ReferenceError: Error #1069: Property selectedItem not found
    on renderers.worksheet.SubThingComboBox and there is no default
    value.
    Once I add selectedItem, then I get this RTE:
    ReferenceError: Error #1069: Property null not found on Thing
    and there is no default value.
    Basically, how do I map the selectedItem of the combobox to
    Thing.subThing?

    The override set data() method returns a reference to the
    current "thing". On combo box change, you can use this reference to
    set the property in the thing item.
    If you do not know what the "overide set data()" method is,
    you need to study some more on itemRenderers. There are several
    examples on cflex.net and many elsewhere on the net.
    Tracy

  • Datagrid combobox itemEditor event

    I have a datagrid populated by managed arraycollection by
    dataservice. One of the columns has an item Editor using a
    component ComboBox. Sofar all is fine but I have not been able to
    define an event that will be triggered when the combobox has
    changed and a new value is selected. I have tried itemEditEnd which
    will only trigger if one clicks outside the itemEditor which
    generates an "other" event. "Change" method of DG will trigger an
    event before any selection is made. Any ideas? I need the trigger
    to commit the change to database.
    Thx

    Hi,
    I'm sorry to bug you with a non-technical discussion, but I
    am a recruiter in San Diego. My client is in need of 3 Senior Flex
    Developers for their project. I have had an extremely rough time
    finding someone for this position. Would you be interested in this
    position, or do you know of anyone that might be? We do pay
    referral fees. This position may be open to telecommuting.
    Job Description:
    They are in the midst of a major re-architecting of their
    Corporate Management system utilizing many cutting edge
    technologies. As it relates to the position they are using Flex as
    their UI.
    This is either a contract, or a full-time position.
    Pay: Market Rate
    Thanks for your help!
    Natalie Fay
    Outsource Technical
    www.ostechnical.com
    [email protected]
    858.874.5637

  • Sort DataGrid with dataprovider XMLisCollection

    I can't get my datagrid to sort when I have a
    XMLListcollection as the dataprovider and I have to use a
    labelfunction to get the records to display because of the
    namespace in the XML (Replicating a .NET web service).
    Can someone help, Please?
    I have the following code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="vertical" creationComplete="initApp()" >
    <mx:Script>
    <![CDATA[
    import mx.controls.dataGridClasses.DataGridColumn;
    import mx.controls.DataGrid;
    import mx.events.DataGridEvent;
    import mx.collections.*;
    import mx.controls.Alert;
    import mx.formatters.DateFormatter;
    //the dataProvider for the DG
    [Bindable]
    private var _xlc:XMLListCollection;
    [Bindable]
    private var sortA:Sort;
    // The sort fields used to determine the sort.
    private var sortBySeverity:SortField;
    private var sortByRequestor:SortField;
    public function initApp():void
    namespace myNameS = "myNamespace.Test";
    use namespace myNameS;
    _xlc = new
    XMLListCollection(GetRequestList.*..SafRequestListVO);
    //testing element values
    trace(GetRequestList.*..SafRequestListVO.SeverityLevel);
    sortA = new Sort();
    sortBySeverity = new SortField("SeverityLevel", true, true);
    sortByRequestor = new SortField("Requestor", true);
    sortA.fields=[sortBySeverity, sortByRequestor];
    _xlc.sort=sortA;
    _xlc.refresh();
    dg.dataProvider = _xlc;
    dg.rowCount=_xlc.length +1;
    /**labelFunction to return data to DG by reference of
    dataField*/
    private function LF(item:Object,
    column:DataGridColumn):Object
    namespace myNameS = "myNamespace.Test";
    use namespace myNameS;
    var colDataField:Object = column.dataField;
    switch (colDataField) //logic to determine which node to get
    the data from
    case "SAFNumber":
    return item.SAFNumber;
    break;
    case "RequestDate":
    var date:String = new String(item.RequestDate).toString();
    var df:DateFormatter = new DateFormatter();
    df.formatString = "YYYY-MM-DD";
    return df.format(date);
    break;
    case "SeverityLevel":
    return item.SeverityLevel;
    break;
    case "Requestor":
    return item.Requestor;
    break;
    case "IssuedToDepartment":
    return item.IssuedToDepartment;
    break;
    default:
    return item.dataField;
    break;
    ]]></mx:Script>
    <mx:Canvas id="datagridParent" borderStyle="solid"
    height="450" width="100%" >
    <mx:DataGrid id="dg" width="100%" height="100%"
    rowCount="5" labelFunction="LF">
    <mx:columns>
    <mx:DataGridColumn dataField="SAFNumber"
    headerText="SAFNumber"/>
    <mx:DataGridColumn dataField="Requestor"
    headerText="Requestor"/>
    <mx:DataGridColumn dataField="RequestDate"
    headerText="RequestDate"/>
    <mx:DataGridColumn dataField="IssuedToDepartment"
    headerText="IssuedToDepartment"/>
    <mx:DataGridColumn dataField="SeverityLevel"
    headerText="SeverityLevel"/>
    </mx:columns>
    </mx:DataGrid>
    </mx:Canvas>
    <mx:XML id="GetRequestList" format="e4x">
    <GetRequestListResponse xmlns="myNamespace.Test">
    <GetRequestListResult>
    <SafRequestListVO>
    <RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3301</RequestGuid>
    <SAFNumber>1</SAFNumber>
    <RequestDate>03/24/2007</RequestDate>
    <Requestor>Michael</Requestor>
    <IssuedToDepartment>1</IssuedToDepartment>
    <IssuedToArea>3</IssuedToArea>
    <IssuedByDepartment>string</IssuedByDepartment>
    <Problem>Problem Details........Problem
    Details........</Problem>
    <SeverityLevel>3</SeverityLevel>
    <CurrentState>string</CurrentState>
    </SafRequestListVO>
    <SafRequestListVO>
    <RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3302</RequestGuid>
    <SAFNumber>2</SAFNumber>
    <RequestDate>02/21/2006</RequestDate>
    <Requestor>Bill</Requestor>
    <IssuedToDepartment>1</IssuedToDepartment>
    <IssuedToArea>2</IssuedToArea>
    <IssuedByDepartment>string</IssuedByDepartment>
    <Problem>Problem Details........Problem
    Details........Problem Details........Problem
    Details........Problem Details........</Problem>
    <SeverityLevel>1</SeverityLevel>
    <CurrentState>string</CurrentState>
    </SafRequestListVO>
    <SafRequestListVO>
    <RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3303</RequestGuid>
    <SAFNumber>3</SAFNumber>
    <RequestDate>01/06/2007</RequestDate>
    <Requestor>Jonathan</Requestor>
    <IssuedToDepartment>8</IssuedToDepartment>
    <IssuedToArea>2</IssuedToArea>
    <IssuedByDepartment>string</IssuedByDepartment>
    <Problem>string</Problem>
    <SeverityLevel>1</SeverityLevel>
    <CurrentState>string</CurrentState>
    </SafRequestListVO>
    <SafRequestListVO>
    <RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3304</RequestGuid>
    <SAFNumber>4</SAFNumber>
    <RequestDate>03/27/2007</RequestDate>
    <Requestor>Bill</Requestor>
    <IssuedToDepartment>7</IssuedToDepartment>
    <IssuedToArea>2</IssuedToArea>
    <IssuedByDepartment>string</IssuedByDepartment>
    <Problem>Problem Details........Problem
    Details........Problem Details........Problem
    Details........Problem Details........</Problem>
    <SeverityLevel>3</SeverityLevel>
    <CurrentState>string</CurrentState>
    </SafRequestListVO>
    <SafRequestListVO>
    <RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3305</RequestGuid>
    <SAFNumber>5</SAFNumber>
    <RequestDate>12/21/2006</RequestDate>
    <Requestor>Mike</Requestor>
    <IssuedToDepartment>4</IssuedToDepartment>
    <IssuedToArea>2</IssuedToArea>
    <IssuedByDepartment>string</IssuedByDepartment>
    <Problem>string</Problem>
    <SeverityLevel>2</SeverityLevel>
    <CurrentState>string</CurrentState>
    </SafRequestListVO>
    <SafRequestListVO>
    <RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3306</RequestGuid>
    <SAFNumber>6</SAFNumber>
    <RequestDate>04/02/2007</RequestDate>
    <Requestor>Nick</Requestor>
    <IssuedToDepartment>2</IssuedToDepartment>
    <IssuedToArea>2</IssuedToArea>
    <IssuedByDepartment>string</IssuedByDepartment>
    <Problem>Problem Details........Problem
    Details........Problem Details........Problem
    Details........Problem Details........</Problem>
    <SeverityLevel>3</SeverityLevel>
    <CurrentState>string</CurrentState>
    </SafRequestListVO>
    <SafRequestListVO>
    <RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3307</RequestGuid>
    <SAFNumber>7</SAFNumber>
    <RequestDate>03/27/2007</RequestDate>
    <Requestor>Sandeep</Requestor>
    <IssuedToDepartment>4</IssuedToDepartment>
    <IssuedToArea>2</IssuedToArea>
    <IssuedByDepartment>string</IssuedByDepartment>
    <Problem>Problem Details........Problem
    Details........Problem Details........Problem
    Details........</Problem>
    <SeverityLevel>2</SeverityLevel>
    <CurrentState>string</CurrentState>
    </SafRequestListVO>
    </GetRequestListResult>
    </GetRequestListResponse>
    </mx:XML>
    </mx:Application>

    Michael, I am sorry, but I myself have significant difficulty
    with xml namespaces. I have managed to get some examples working
    but only by trial and error and studying up on Namespace in the
    docs.
    http://www.cflex.net/showfiledetails.cfm?ChannelID=1&Object=File&objectID=582
    I am just not good enough with them to be able to tell you
    what you need to do.
    Tracy

  • Problem with selectedItem (DataGrid) when dataProvider is XML

    I have a problem.
    I want to load my DataGrid with data from XML returned via
    Struts. I have set up a test environment for the time being and I
    can LOAD the data into the grid just fine, but when I want to refer
    to it after it is loaded (with selectedItem) I am having all sorts
    of problems. Namely, I can't access any of the data in
    selectedItem. I can't even seem to make it show up in a string...
    the only way I can access values is individually using :
    selectedItem["@attribute"] which is NOT what I want to do...
    can anyone tell me what I am doing wrong? Is there no way I
    can convert the xml to an object (or is that even the problem)?
    Here is code to show exactly what I mean:
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="vertical" creationComplete="doDummySearch()">
    <mx:Script>
    <![CDATA[
    import mx.utils.ArrayUtil;
    import mx.controls.Alert;
    //this dummyXML is in place of the response from the server
    for now...
    private var dummyXML:XML =
    <root>
    <dummyData priority='0' dealerCode='A00-1023'
    phoneNo='0343442323' />
    <dummyData priority='1' dealerCode='B00-1033'
    phoneNo='0343442323' />
    <dummyData priority='0' dealerCode='DER-0666'
    phoneNo='0343442323' />
    </root>
    private function doDummySearch():void {
    search_dg.dataProvider = dummyXML.children();
    private function select():void {
    var s:String = "";
    s+=search_dg.selectedItem["@dealerCode"]+"\n";
    s+="all data: \n";
    for each (var entry:* in search_dg.selectedItem) {
    s+=entry+"\n";
    s+="^-why is this blank?\n";
    s+="selectedItem.toString():
    "+search_dg.selectedItem.toString()+" <-why is this blank?";
    mx.controls.Alert.show(s, "selected data:");
    ]]>
    </mx:Script>
    <mx:DataGrid id="search_dg" />
    <mx:Button label="select item" click="select()" />
    </mx:Application>

    Or even better, you can use the new E4X support in Flex, to
    directly read from the XML
    See this example
    main.xml
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    xmlns="*" layout="vertical" >
    <mx:Script>
    <![CDATA[
    private function select():void {
    var s:String = "";
    s+="Symbol = "+search_dg.selectedItem.Symbol+"\n";
    s+="Quantity = "+search_dg.selectedItem.Quantity+"\n";
    s+="Price = "+search_dg.selectedItem.Price+"\n";
    s+="Value = "+search_dg.selectedItem.Value+"\n";
    mx.controls.Alert.show(s, "selected data:");
    ]]>
    </mx:Script>
    <mx:XML format="e4x" id="portfolioModel"
    source="portfolio.xml" />
    <mx:DataGrid id="search_dg"
    dataProvider="{portfolioModel.security}">
    <mx:columns>
    <mx:DataGridColumn dataField="Symbol"
    headerText="Symbol"/>
    <mx:DataGridColumn dataField="Quantity"
    headerText="Quantity"/>
    <mx:DataGridColumn dataField="Price"
    headerText="Price"/>
    <mx:DataGridColumn dataField="Value"
    headerText="Value"/>
    </mx:columns>
    </mx:DataGrid>
    <mx:Button label="select item" click="select()" />
    </mx:Application>
    portfolio.xml
    <portfolio>
    <security>
    <Symbol>MSFT</Symbol>
    <Quantity>10000</Quantity>
    <Price>20.56</Price>
    <Value>1</Value>
    </security>
    <security>
    <Symbol>IBM</Symbol>
    <Quantity>3000</Quantity>
    <Price>80.21</Price>
    <Value>1</Value>
    </security>
    <security>
    <Symbol>ADBE</Symbol>
    <Quantity>10000</Quantity>
    <Price>32.56</Price>
    <Value>1</Value>
    </security>
    <security>
    <Symbol>GOOG</Symbol>
    <Quantity>3000</Quantity>
    <Price>380.21</Price>
    <Value>1</Value>
    </security>
    </portfolio>

  • Setting Combobox 'dataProvider' @runtime and using 'labelFunction'

    I have 2 comboboxes which are related i.e. when i change cb-1 i need to display values in cb-2 (cb-2 list varies with the value selected). I have simplified my case but this is what my problem is. After i set 'cb-2.dataProvider' when does 'labelFunction' for cb-2 get called?
    If i am not clear enough please let me know. Here is the code.....
    private function cb-1Change(event:ListEvent):void
    {// This will be a dynamic one using the value selected in cb-1
    cb-2.dataProvider = __model.someList.getItemAt(0).cb-2VOList;  // extracting from a Map kind object
    // This Label function is never getting called
    private function displayCB-2Label(item:Object):String{ 
         // something
    <mx:ComboBox d="cb-1"           dataProvider="{__model.cb-1List}"
              change="cb-1Change(event)"
    />
    <mx:ComboBox d="cb-2"
              labelFunction="displayCB-2Label(event)"
              change="cb-1Change(event)"
    />
              change="cb-1Change(event)"
    />  

    Ryan,
            Thanks for the answer. I think i was not clear on my questions. Let me try it again:
    Requirement:
           When ever user change cb-1 value it should populate a new list and assign to cb-2 dataProvider i.e. cb-2 list should refresh. cb-2 needs to display right label based on its 'labelFunction'.
    cb1 -  List of Strings
    cb2 -  List of VO's in the following format
    ListVO:
           public var code:String;    // This Code is what user selects in cb-1
           public var  listValues:ArrayCollection;  // List of PlainVO's
    PlainVO:
         public var name:String;
         public var value:String;
    Also from your answer how can i call 'cb-2 label function in cb-1 change', i mean cb-2 labelFunction expects current 'ListVO' object...right?

  • Webservice as Combobox dataprovider

    Does anyone have an example of how to use a webservice as a
    dataprovider to a combobox?
    I would like to see how to set the label and data values for
    the combobox lookup list.
    Thank you ahead of time.
    Bill Brittain

    You need a little function to find the index of the item in
    the data provider and then sets the combo box's selected index to
    that number. This example uses the
    label, but you just as easily use the
    data.
    label
    public function setSelectedLabel(label:String):void
    for(var i:int=0; i< this.dataProvider.length; i++)
    if(this.dataProvider.label==label)
    this.selectedIndex=i
    simon

  • Combobox autoSize to item width

    Is there a way of setting the spark ComboBox component width to fit it's labels? I am attempting to get the component to be a snug fit to its longest item label.
    Thanks in advance.

    ComboBox does not automatically size itself to fit the largest item in its dataProvider.  The closest you can come to this behavior is to use typicalItem to set the size of ComboBox based on a known object.

Maybe you are looking for