Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 374425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:24:15+00:00 2026-05-12T14:24:15+00:00

I’m going spare trying to figure out the correct way to embed a ComboBox

  • 0

I’m going spare trying to figure out the “correct” way to embed a ComboBox inside a Flex (3.4) DataGrid. By Rights (e.g. according to this page http://blog.flexmonkeypatches.com/2008/02/18/simple-datagrid-combobox-as-item-editor-example/) it should be easy, but I can’t for the life of me make this work.

The difference I have to the example linked above is that my display value (what the user sees) is different to the id value I want to select on and store in my data provider.

So what I have is:

<mx:DataGridColumn headerText="Type" width="200" dataField="TransactionTypeID" editorDataField="value" textAlign="center" editable="true" rendererIsEditor="true">
    <mx:itemRenderer>
        <mx:Component>
            <mx:ComboBox dataProvider="{parentDocument.transactionTypesData}"/>
        </mx:Component>
    </mx:itemRenderer>
</mx:DataGridColumn>

Where transactionTypesData has both ‘data’ and ‘label’ fields (as per what the ComboBox – why on earth it doesn’t provide both a labelField and idField I’ll never know).

Anyway, the above MXML code doesn’t work in two ways:

  1. The combo box does not show up with any selected item.
  2. After selecting an item, it does not store back that selected item to the datastore.

So, has anyone got a similar situation working?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:24:15+00:00Added an answer on May 12, 2026 at 2:24 pm

    While Jeff’s answer is a partial answer for one approach for this (see http://flex.gunua.com/?p=119 for a complete example of this being used to good effect), it isn’t as general as I wanted.

    Thankfully, I finally found some great help on Experts Exchange (the answers by hobbit72) describes how to create a custom component that works in a grid as a ItemRenderer.
    I’ve extended that code to also support using the combo box as an ItemEditor as well. The full component is as follows:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:ComboBox
        xmlns:mx="http://www.adobe.com/2006/mxml" 
        dataChange="setSelected()" 
        change="onSelectionChange(event)"
        focusEnabled="true">
        <mx:Script>
            <![CDATA[
                import mx.events.DataGridEvent;
                import mx.events.ListEvent;
                import mx.controls.dataGridClasses.DataGridListData;
    
                private var _ownerData:Object;
                private var _lookupField:String = "value";
    
                // When using this component as an itemEditor rather than an itemRenderer
                // then set ' editorDataField="selectedItemKey"' on the column to 
                // ensure that changes to the ComboBox are propogated.
                [Bindable] public var selectedItemKey:Object;
    
                public function set lookupField (value:String) : void {
                    if(value) {
                        _lookupField = value;
                        setSelected();
                    }
                }           
                override public function set data (value:Object) : void {
                    if(value) {                    
                        _ownerData = value;
                        setSelected();
                    }
                }
                override public function get data() : Object {
                    return _ownerData;
                }            
                private function setSelected() : void {
                    if (dataProvider && _ownerData) {
                        var col:DataGridListData = DataGridListData(listData);
                        for each (var dp:Object in dataProvider) {
                            if (dp[_lookupField] == _ownerData[col.dataField]) {
                                selectedItem = dp;
                                selectedItemKey = _ownerData[col.dataField];
                                return;     
                            }
                        }                    
                    }
                    selectedItem = null;
                }
                private function onSelectionChange (e:ListEvent) : void {
                    if (selectedItem && _ownerData) {                    
                        var col:DataGridListData = DataGridListData(listData);
                        _ownerData[col.dataField] = selectedItem[_lookupField];
                        selectedItemKey = selectedItem[_lookupField];
                    }
                }                   
            ]]>
        </mx:Script>    
    </mx:ComboBox> 
    

    Using this component is straight forward. As an ItemRenderer:

    <mx:DataGridColumn headerText="Child" dataField="PersonID" editable="false" textAlign="center">
      <mx:itemRenderer>
        <mx:Component>
          <fx:GridComboBox dataProvider="{parentDocument.childrenData}" labelField="Name" lookupField="PersonID" change="dispatchEvent(new mx.events.DataGridEvent(mx.events.DataGridEvent.ITEM_FOCUS_OUT, true, true))"/>
        </mx:Component>
      </mx:itemRenderer>                      
    </mx:DataGridColumn>
    

    Using this component is straight forward. And as an ItemEditor:

    <mx:DataGridColumn labelFunction="lookupChildName" headerText="Child" dataField="PersonID" editable="true" editorDataField="selectedItemKey">
        <mx:itemEditor>
            <mx:Component>
                <fx:GridComboBox dataProvider="{parentDocument.childrenData}" labelField="Name" lookupField="PersonID" change="dispatchEvent(new mx.events.DataGridEvent(mx.events.DataGridEvent.ITEM_FOCUS_OUT, true, true))"/>
            </mx:Component>
         </mx:itemEditor>      
    </mx:DataGridColumn>
    

    Note that when using it as an ItemEditor, a custom labelFunction (that looks up the Name from the PersonID in my case) must be used, otherwise you only see the key in the grid when the field isn’t being edited (not a problem if your keys/values are the same).

    Note that in my case, I wanted the item focus out event to propogate up to provide immediate feedback to the user (my DataGrid has itemFocusOut="handleChange()"), hence the change event creating an ITEM_FOCUS_OUT event.

    Note that there are probably simpler ways to have a ComboBox as an ItemEditor when you don’t mind the ComboBox only shown when the user clicks on the cell to edit. The approach I wanted was a generic way to show a combo box in a DataGrid for all rows, and being editable and with decent event propogation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.