Hi,
I need to implement a custom component to have a selectable list with a maximum selected items.
that is, when the selected items reach the max number, all un-selected items will be gray out.
Now I am able to use DataGrid control to display a selectable "checkbox" (through itemRenderer) at first column, to let user select the item.
And the list name in second column.
But I can't find a way to gray out (disable) those un-selected item when max is reached.
Can anyone give any advise?
Here is my code snippet:
SelectableListView.mxml
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" visible="true">
<mx:DataGrid id="list_datagrid" dataProvider="{this.stringList}" showHeaders="false"
editable="false" selectable="true" verticalGridLines="false" borderStyle="none" alternatingItemColors="[#F8F8F0, #FFFFFF]"
left="5" rowCount="16" rowHeight="20" height="83" width="100%" top="0" doubleClickEnabled="true" doubleClick="onDoubleClick(event)" >
<mx:columns>
<mx:DataGridColumn id="listCheckBox_col" dataField="selected" editable = "false"
itemRenderer="ListRenderer" width="18" headerText="" resizable="false" draggable="false"/>
<mx:DataGridColumn id="listName_col" dataField="name" />
</mx:columns>
</mx:DataGrid>
</mx:VBox>
ListRenderer.mxml
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="60" >
<mx:Script>
<![CDATA[
private function setInUse() : void
{
_data.selected = listInUse.selected;
}
]]>
</mx:Script>
<mx:CheckBox id="listInUse" width="18" height="18" click="setInUse()" selected="{_data.selected}"/>
</mx:Canvas>
what is listInUse insdie the itemRenderer? I am not very clear about how you use
it. However there are 2 ways of doing it. Not sure if data.selected can be used
to enable/disable the itemrenderer. So I will asume not. Have an extra bindable
"enabled" property in your dataProvider model. So when you reach the maximum of
selected items iterate through the collection and set the set the enabled
accordingly. The renderer's enabled property is bound to the model's enabled so
it should update accordingly. The other way is to bind the enabled of the
renderer on the selected. But as I said I am not sure how your code works ...
HTH,
C
North America
Europe, Middle East and Africa
Asia Pacific