The text label isn't updating.  The items that get filtered out become 
deselected when you run the filter function.

  Change the label to this:

<mx:Label text="{cboRatings.selectedIndices.length}"/>

  And it appears to update properly.  Must be some oddity with the 
string concatenation you were doing to define the text.  I'm surprised 
it updates correctly when selecting more.

Anyway, this is my full code just in case



<?xml version="1.0" encoding="utf-8"?>
<mx:Application
        xmlns:mx="http://www.adobe.com/2006/mxml";
        layout="absolute"
        width="200" height="350"
        creationComplete="init();">
<mx:Script>
        <![CDATA[
import mx.collections.ArrayCollection;
import mx.utils.StringUtil;
import mx.controls.Alert;
[Bindable]
private var dp:ArrayCollection = new ArrayCollection();

public function myFilter(item:Object):Boolean
{
        /// find the needle in the haystack
        var goodRow:Boolean = true;
        
        var needle:String = txtFilter.text;
        var haystack:String = "";

        needle = StringUtil.trim(needle);
        needle = needle.toLowerCase();
                
        haystack = item.toString().toLowerCase();
        if (haystack.indexOf(needle) < 0)
        {
                goodRow = false;
        }
        return goodRow;
}

private function init():void
{
        var item:Object = new Object();
        
        for (var i:int=1;i<=50;i++)
        {
                dp.addItem('Item ' + i.toString());
        }
//      cboRatings.dataProvider = dp;
        this.dp.filterFunction = myFilter;
//      cboRatings.dataProvider.filterFunction = myFilter;
//      cboRatings.dataProvider.refresh();
}
private function clearForm():void
{
//      cboRatings.selectedIndex=-1;
        txtFilter.text = '';
        cboRatings.dataProvider.refresh();
}
        ]]>
</mx:Script>
        <mx:Panel title="List Component Filter Test" width="100%" height="100%">
        <mx:HBox top="10" left="10">
                <mx:VBox>
                        <mx:HBox>
                                <mx:Label text="Filter:"/>
                                <mx:TextInput id="txtFilter" width="100" 
change="dp.refresh();"/>
                        </mx:HBox>
                        <mx:Label text="{cboRatings.selectedIndices.length}"/>
                        <mx:List id="cboRatings" width="150" height="200" 
labelField="LABEL" 
allowMultipleSelection="true" rowHeight="22" dataProvider="{this.dp}"  />
                        <mx:Button id="btnDoit" label="Clear" 
click="clearForm();"/>
                        <mx:Button id="alert" label="Show" 
click="Alert.show(cboRatings.selectedIndices.length.toString())"/>
                </mx:VBox>
        </mx:HBox>

        
        </mx:Panel>
</mx:Application>


Rick Root wrote:
> So I'm building an application which contains lists of items that I
> want users to be able to filter, select some items, filter again,
> select some more items, etc.
> 
> However, when a selected item is filtered out, when the filter is
> removed, the item is no longer selected.
> 
> Take the following example:
> 
> http://www.it.dev.duke.edu/public/CheckBoxListTest/CheckBoxListTest.html
> 
> select "Item 1" then filter for "Item 2"... don't select anything.
> Remove the filter now.
> 
> Item 1 is no longer selected.  But the label still says it is
> selected.. the label is bound to the
> {cboRatings.selectedIndices.length} property.
> 
> In my test application I can't get it to work the way I want it to at
> all.  In my real application, it works sometimes but not others.
> 
> I thought maybe it was the CheckBoxList component that someone had
> written for me... or the CheckBoxListItemRenderer that was part of
> that component, but i'm finding the same problem in the above test
> application which only uses a simple, standard list component.
> 
> If it makes any different, I'm compiling the application with Flex
> Builder 3 (beta 2).  I've compiled it with the Flex 2.0.1 HF3 SDK and
> the latest Flex 3 beta SDK.
> 
> Why doesn't the list remember what's selected?  Doesn't the filter
> simply prevent an item from displaying?
> 
> Rick
> 
> 

-- 
Jeffry Houser, Technical Entrepreneur, Software Developer, Author, 
Recording Engineer
AIM: Reboog711  | Phone: 1-203-379-0773
--
My Company: <http://www.dot-com-it.com>
My Podcast: <http://www.theflexshow.com>
My Blog: <http://www.jeffryhouser.com>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Enterprise web applications, build robust, secure 
scalable apps today - Try it now ColdFusion Today
ColdFusion 8 beta - Build next generation apps

Archive: http://www.houseoffusion.com/groups/Flex/message.cfm/messageid:4798
Subscription: http://www.houseoffusion.com/groups/Flex/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.37

Reply via email to