Hi, I've got an eventListener listening for keyboard events and a  checkbox in 
a datagrid column, and after I select a checkbox and immediately hit a key, 
then the item selected is not picked up.
If I select a checkbox in the datagrid, then click outside the datagrid, then 
hit a key, then the item selected is recorded properly.
How Can I fix this?  

here is the code, to run the example, click on the two checkboxes, then 
immediatly press a key, only the first name is reported.

example here: http://elizabethcoda.com/datagridCheckbox.swf

code:
<?xml version="1.0"?>
<!-- itemRenderers\inline\CBInlineCellEditor.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
applicationComplete="init()">
    
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
        
            [Bindable]                
            private var myDP:ArrayCollection = new ArrayCollection([
                {label1:"Order #2314", contact:"Marge", 
                    quant:3, solddate:new Date(2005, 0, 1), Sent:false},
                {label1:"Order #2315", contact:"Bart", 
                    quant:3, solddate:new Date(2005, 0, 5), Sent:false}
            ]);
            private function init():void {
                addEventListener(KeyboardEvent.KEY_UP,showSelected);
            }
            private function sent(e:Event):void {
                sent_ta.text = '';
                for(var i:int = 0; i < myDP.length;i ++ ) {
                        if(myDP[i].Sent) {
                                sent_ta.text += " sent to " + myDP[i].contact + 
'\n';
                        }
                }
            }
            private function showSelected(event:KeyboardEvent):void {  
                 sent_ta.text = '';
                             for (var i:int=0; i < myDP.length; i++) {
                                if (myDP[i].Sent) {                             
                                        sent_ta.text += " sent to " + 
myDP[i].contact + '\n';
                                }                        
                        }
               } 
        ]]>
    </mx:Script>

    <mx:DataGrid id="myDG" 
            dataProvider="{myDP}" 
            variableRowHeight="true" 
            width="500" height="250" 
            editable="true">
        <mx:columns>
            <mx:DataGridColumn dataField="label1" 
                headerText="Order #" 
                editable="false"/>
            <mx:DataGridColumn dataField="quant" 
                headerText="Quantity" 
                itemEditor="mx.controls.NumericStepper"  
                editorDataField="value"/>
            <mx:DataGridColumn dataField="solddate" 
                headerText="Date"  
                itemRenderer="mx.controls.DateField" 
                rendererIsEditor="true" 
                editorDataField="selectedDate"/>
            <mx:DataGridColumn dataField="contact" />    
            <mx:DataGridColumn dataField="Sent" 
                itemRenderer="mx.controls.CheckBox" 
                rendererIsEditor="true" 
                editorDataField="selected"/>
        </mx:columns >
    </mx:DataGrid>  
    <mx:Button label="What's sent?" click="sent(event)"/>
    <mx:TextArea id="sent_ta" height="70"/>
</mx:Application>

Reply via email to