Here is the code for the renderer.  I extend Label and add a
dataProvider to make it act like a combobox, so that I can specify an
index to show.  That way it doesn't look like a combobox when it
renders.  I'm not doing anything special to look for a change, just
implementing what I thought was necessary.

        public class LabelWithDownArrow extends Label
        {
                
                private var _dataProvider:ArrayCollection = null;

                private var _prompt:String                = null;
                private var defaultPrompt:String  = "Select Item...";
                private var _selectedIndex:int = -1;
                
                public function LabelWithDownArrow()
                {
                        super();
                }
                
                public function set dataProvider(value:ArrayCollection):void {
                        _dataProvider = value;
                }
                
                public function get dataProvider():ArrayCollection {
                        return _dataProvider;
                }

                public function set selectedIndex(value:int):void {
                        _selectedIndex = value;
                }
                
                public function get selectedIndex():int {
                        return _selectedIndex;
                }
                
                public function set prompt(value:String):void {
                        _prompt = value;
                }
                
                public function get prompt():String {
                        return _prompt;
                }
                
                override protected function updateDisplayList(w:Number, 
h:Number):void {
                        super.updateDisplayList(w-15, h); // subtract from 
width to allow
for down arrow

                        var g:Graphics = graphics;
        
                        g.clear();
                        
                        // add arrow to box
                        // Draw the triangle.
                        g.beginFill(0x000000); // black
                        g.moveTo(w - 11.5, h / 2 + 3);
                        g.lineTo(w - 15, h / 2 - 2);
                        g.lineTo(w - 8, h / 2 - 2);
                        g.lineTo(w - 11.5, h / 2 + 3);
                        g.endFill();
                }

                // method used to change what is displayed
                [Bindable]
                override public function set data(value:Object):void {
                        super.data = value;

                        if (listData != null && dataProvider != null) {         
        

                                // now iterate through dp to find a matching 
data value, when
found put its label in the Label widget                                 
                                var dpLen:int = dataProvider.length;
                                for (var j:int=0; j<dpLen; j++) {
                                        if (dataProvider.getItemAt(j).data ==
data[DataGridListData(listData).dataField]) { // found match
                                                this.text = 
dataProvider.getItemAt(j).label; // + " " +
dp.getItemAt(j).data;
                                                trace('found 
LabelWithDownArrow');
                                                return;
                                        }
                                }

                                // not found, so show comboBox prompt
                                if (prompt == null || prompt == "-1" || 
selectedIndex == -1)
                                        this.text = defaultPrompt;
                                else if (selectedIndex < dataProvider.length)
                                        this.text = 
dataProvider.getItemAt(selectedIndex).label;
                                else
                                        this.text = "";
                                
                                trace('not found LabelWithDownArrow');
                        }
                }

        }

--- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> What does the renderer look like?  How will it detect changes to the
> underlying data?
> 
>  
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of j_lentzz
> Sent: Wednesday, January 02, 2008 7:21 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Datagrid Renderer not showing updated
> ArrayCollection
> 
>  
> 
> Hi,
> 
> I've got a datagrid with a custom renderer. I'm not editing in the
> datagrid, but when a row is selected, I populate some TextInputs and
> ComboBoxes to let them edit the data. When they are done, I use
> itemUpdated on the datagrid ArrayCollection. This seems to work just
> fine. However, after they edit the data, it isn't being updated in
> the datagrid. I can select a different row, then select the original
> row and the new data appears in the edit locations, but only the old
> data is displayed in the datagrid. I've tried all the invalidateXXX
> methods I could find, but nothing seems to get the datagrid do display
> the new data. Also, I can set a breakpoint, examine the
> arraycollection the datagrid uses, and the correct data is present -
> just not being displayed. What do I need to do to get the datagrid to
> be forced to used the arraycollection and update all the
> itemrenderers? I'm using 2.01, would Flex 3 be better?
> 
> Thanks,
> 
> John
>


Reply via email to