Hi Martina,

whenever the dataprovider is updated, you need to refresh the selectedIndex. You can use a binding function for this. This should work with cairngorm also. Here is a little example.

<?xml version=" 1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical"
    >

    <mx:Script>
        <![CDATA[

            import mx.collections.ArrayCollection;
            import mx.binding.utils.ChangeWatcher;
       
            private var generation : int = 0;
       
            [Bindable]
            private var dataProvider : ArrayCollection = createData();
           
            [Bindable]
            private var selectedIndex : int = 0;
           
            private function createData() : ArrayCollection
            {
                generation++;
               
                var result : ArrayCollection = new ArrayCollection();
                for( var i : int = 0; i < 10; i++ )
                {
                    result.addItem(" item " + i + ":" + generation);
                }
                return result;
            }
           
            private function onChange( event : Event ) : void
            {
                selectedIndex = event.target.selectedIndex;
            }
           
            private function assignDataProvider() : void
            {
                dataProvider = createData();
            }
           
            private function assignSelectedIndex() : void
            {
                cb.selectedIndex = selectedIndex;
            }

            private function onUpdateDataProvider( dp : Object ) : Object           
            {
                cb.callLater( assignSelectedIndex );
                return dp;
            }
        ]]>
    </mx:Script>   
   
    <mx:ComboBox id="cb"
        dataProvider="{ onUpdateDataProvider( dataProvider )}"
        selectedIndex="{ selectedIndex }"
        change="onChange( event )"
        />
    <mx:Button
        label="assign new data"
        click="assignDataProvider();"
        />
</mx:Application>

Cheers,
Ralf.

On 7/27/06, Martina Smith < [EMAIL PROTECTED]> wrote:
Thank Ralf,
 
Could you please elaborate on this?
 
I am using cairngorm architecture. According to this architecture, the command should modify the model, and the view will receive the updated values through binding with model.
 
The problem here is that the model has the updated values, but the view is not refreshed with the latest values.
 
I tried using callLater function but it did not silve the problem. One more problem with callLater is that it works only with UIComponent.
 
Thanks & Regards,
Martina.


Ralf Bokelberg < [EMAIL PROTECTED]> wrote:
Hi Martina,

you could try to set the selectedIndex using callLater after the dataProvider has changed.

Cheers,
Ralf.

On 7/24/06, Martina Smith <[EMAIL PROTECTED]> wrote:
Hi,
 
I am using the ComboBox component (<mx:ConboBox>) in flex 2.0. I am attaching the dataprovider to the combobox by the bind property. The Dataprovider is actually an array. The items in the dataprovider get refreshed dynamically.
 
Here is how I populate the combobox items:
<mx:ComboBox id="contactListDropDown" selectedIndex="{TestModelLocator.getInstance ().selectedUserIndexAsNumber}" dataProvider="{TestModelLocator.getInstance ().dataProviderArray}" change="contactListChangeHandler(event)"/> 
 
I want to maintain the old selectedIndex everytime I refresh the dataprovider.
 
The problem I am facing is that the 'selectedIndex' property is not getting refreshed even if I store the old value. The ' selectedIndex' resets to 0 once the dataprovider is refreshed.
 
I need to get this thing solved as my functionality depends on the current selected index of the combobox.
 
Thanks in Advance,
 
Martina
 
 
 

Find out what India is talking about on Yahoo! Answers India.



--
Ralf Bokelberg < [EMAIL PROTECTED]>
Flex & Flash Consultant based in Cologne/Germany


Here's a new way to find what you're looking for - Yahoo! Answers




--
Ralf Bokelberg <[EMAIL PROTECTED]>
Flex & Flash Consultant based in Cologne/Germany __._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to