Very Strange behavior in custom dataGrid
        Posted  
        
            by Markus
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Markus
        
        
        
        Published on 2010-03-16T16:55:51Z
        Indexed on 
            2010/03/16
            17:21 UTC
        
        
        Read the original article
        Hit count: 288
        
Hi everybody,
I asked this question already in a former post, but nobody could answer this question correctly. So I try to post the problem again, to make sure it's not a bug. I have a dataGrid with a custom itemRenderer. Everytime I tab at least two times on the dataGrid, the cell below the one I taped gets selected. This doesn't happen if I uncomment the code in the method saveBackDataGridContent()!
The second problem is that if the Line is shorter than the entered text, a horizontalScrollBar will get active, although I set setStyle("horizontalScrollPolicy", "off");...
Who can solve that one?
CustomRenderer.mxml:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="dataService.send()">
<mx:Script>
    <![CDATA[
        import components.ChoiceRenderer;
        import mx.rpc.events.ResultEvent;
        import mx.events.DataGridEvent;
        private function resultHandler(event:ResultEvent):void {            
            var doc:XML = event.result as XML;
            testGrid.dataProvider = doc.Records.BackSide;           
        }
        private function saveBackDataGridContent(event:DataGridEvent):void{                 
            testGrid.dataProvider[event.rowIndex].TextElement = event.currentTarget.itemEditorInstance.text;                        
        }               
        ]]>
</mx:Script>
<mx:HTTPService id="dataService" result="resultHandler(event)" url = "data/example.xml" resultFormat="e4x"/>
<mx:DataGrid id="testGrid" editable="true" itemEditEnd="saveBackDataGridContent(event)">
      <mx:columns>
        <mx:DataGridColumn itemRenderer="components.ChoiceRenderer" width="230"/>
  </mx:columns>
</mx:DataGrid>
</mx:Application>
ChoiceRenderer.as
package components
{
    import mx.containers.HBox;
    import mx.controls.CheckBox;
    import mx.controls.Label;
    public class ChoiceRenderer extends HBox
    {
        private var correctAnswer:CheckBox;
        private var choiceLabel:Label;
        public function ChoiceRenderer()
        {
            super();                                
            setStyle("horizontalScrollPolicy", "off");
            correctAnswer = new CheckBox;
            addChild(correctAnswer);            
            choiceLabel = new Label;
            addChild(choiceLabel);      
        }
        override public function set data(xmldata:Object):void{
            if(xmldata.name() == "BackSide"){
                super.data = xmldata.TextElement[0];
                choiceLabel.text = xmldata.TextElement[0].toString();
            }
        }
    }
}
example.xml
<TopContainer>
<Records>
    <BackSide>
        <TextElement>first</TextElement>                            
    </BackSide>
    <BackSide>
        <TextElement>second</TextElement>                       
    </BackSide>
    <BackSide>
        <TextElement>third</TextElement>                            
    </BackSide>
    <BackSide>
        <TextElement>fourth</TextElement>                       
    </BackSide>
    <BackSide>
        <TextElement>fifth</TextElement>                        
    </BackSide>
    <BackSide>
        <TextElement>sixth</TextElement>                        
    </BackSide>
</Records>
Thanks Markus
© Stack Overflow or respective owner