Steve thanks for your reply.

My aim is to draw horizontal line for entire grid, not for single item.
Please give me a clue 

thanks a lot.

 Thanks & Regards,
Venkat.




________________________________
From: valdhor <[email protected]>
To: [email protected]
Sent: Wed, 16 December, 2009 10:15:20 AM
Subject: [flexcoders] Re: drawing horizontal line in ADG based on data

  
You have completely gone down the wrong track here.

If you need to do anything in a datagrid based on data in the dat provider, you 
need to use an item renderer. I would recommend reading Alex Harui's blog 
postings regarding Item Renderers and also to modify someone's working code 
before embarking on creating your own.

The following is an example showing how to draw a horizontal line based on data 
in the grid:

<?xml version="1.0" encoding="utf- 8"?>
<mx:Application xmlns:mx="http: //www.adobe. com/2006/ mxml" layout="absolute" 
    creationComplete= "onCreationCompl ete()">
    <mx:Script>
        <![CDATA[
            import mx.collections. SortField;
            import mx.collections. Sort;
            import mx.collections. IHierarchicalCol lectionView;
            
            [Bindable] private var myDP:Array = [
                {Office:"Atlanta" ,Month:"Oct. 2009",Sales: "2000",Rejection 
s:"102",SortDate :new Date('10/1/2009' )},
                {Office:"Atlanta" ,Month:"Sept. 2009",Sales: "2000",Rejection 
s:"102",SortDate :new Date('9/1/2009' )},
                {Office:"Atlanta" ,Month:"Aug. 2009",Sales: "1000",Rejection 
s:"102",SortDate :new Date('8/1/2009' )},
                {Office:"Atlanta" ,Month:"Jul. 2009",Sales: "2000",Rejection 
s:"102",SortDate :new Date('7/1/2009' )},
                {Office:"Atlanta" ,Month:"Jun. 2009",Sales: "2000",Rejection 
s:"102",SortDate :new Date('6/1/2009' )},
                {Office:"Atlanta" ,Month:"May 2009",Sales: "2000",Rejection 
s:"102",SortDate :new Date('5/1/2009' )},
                {Office:"Dallas" ,Month:"Oct. 2009",Sales: "2000",Rejection 
s:"102",SortDate :new Date('10/1/2009' )},
                {Office:"Dallas" ,Month:"Sept. 2009",Sales: "1000",Rejection 
s:"102",SortDate :new Date('9/1/2009' )}
            ];
                    
            private function onCreationComplete( ):void
            {
                gc.refresh() ; 
                dg.validateNow( );
            
                var sort:Sort = new Sort();
                sort.fields = [new SortField("SortDate ")];
                IHierarchicalCollec tionView( dg.dataProvider) .sort = sort;
                IHierarchicalCollec tionView( dg.dataProvider) .refresh( );
            }
        ]]>
    </mx:Script>
    <mx:AdvancedDataGrid id="dg" height="80%" width="80%" textAlign="center">
        <mx:dataProvider>
            <mx:GroupingCollecti on id="gc" source="{myDP} ">
                <mx:Grouping>
                    <mx:GroupingField name="Office" />
                </mx:Grouping>
            </mx:GroupingCollect ion>
        </mx:dataProvider>
         <mx:columns>
            <mx:AdvancedDataGrid Column dataField="Month" textAlign="left" />
            <mx:AdvancedDataGrid Column dataField="Sales" textAlign="left" 
itemRenderer= "BGRenderer" />
            <mx:AdvancedDataGrid Column dataField="Rejectio ns" 
textAlign="left" itemRenderer= "BGRenderer" />
        </mx:columns>
    </mx:AdvancedDataGri d>
</mx:Application>

And the item renderer (BGRenderer.as) :
package
{
    import flash.display. Graphics;
    import mx.controls. Text;
    import mx.controls. dataGridClasses. DataGridListData ;
    import mx.utils.StringUtil ; 
    
    public class BGRenderer extends Text
    {
        public function BGRenderer()
        {
            super();
        }

        override public function set data(value:Object) :void
        {
            if(value != null)
            {
                super.data = value;
                text = StringUtil.trim( value[DataGridLi stData(listData) 
.dataField] );
            }
        }
        
        override protected function updateDisplayList( unscaledWidth: Number, 
unscaledHeight: Number):void 
        { 
            super.updateDisplay List(unscaledWid th, unscaledHeight) ;
            if(data != null && data.Sales == 2000)
            {
                var g:Graphics = graphics; 
                g.clear();
                g.lineStyle( 1, 0x00ff00);
                g.moveTo(0, this.height / 2);
                g.lineTo(this. width, this.height / 2);
            }
        }
    }
}


HTH.



Steve


--- In flexcod...@yahoogro ups.com, venkateswarlu naidu <contactvenku@ ...> 
wrote:
>
> Tried below but still getting the horizontal grid lines drawn for all rows 
> when i start scrolling down :(
> 
> 1.
> ============ ========= ========= ========= =====
> override protected function drawHorizontalLine( s:Sprite, rowIndex:int, 
> color:uint, y:Number):void { 
>      if(indexToItemRende rer(rowIndex) != null) { 
>          var myObj:Object = indexToItemRenderer (rowIndex) .data; 
>          var g:Graphics = s.graphics; 
>          if (myObj.name == "John") { 
>              g.lineStyle( 1, 0x0000ff); 
>              g.moveTo(0, y); 
>              g.lineTo(width, y); 
>          } else { 
>              g.lineStyle( 1, 0x000000); 
>              g.moveTo(0, y); 
>              g.lineTo(width, y); 
>          } 
>      } 
> } 
> ------------ ----
> 2.
> ============ ========= =
> 
>  override protected function drawRowBackgrounds( ):void { 
>               super.drawRowBackgr ounds(); 
> 
>              var rowBGs:Sprite = 
> Sprite(listContent. getChildByName( "rowBGs") ); 
>              var lineCol:uint = getStyle("horizonta lGridLineColor" ); 
> 
>              if (!rowBGs) 
>              { 
>                  rowBGs = new FlexSprite() ; 
>                  rowBGs.mouseEnabled = false; 
>                  rowBGs.name = "rowBGs"; 
>                  listContent. addChildAt( rowBGs, 0); 
>              } 
>              var g:Graphics=rowBGs. graphics; 
>              var curRow:int = 0; 
>              var n:int = listItems.length; 
> 
>              while (curRow < n) 
>              { 
>                  try { 
>                      var myObj:Object = listItems[curRow] [0].data; 
>                      if (myObj.phone == "555-219-2270" ) { 
>                          g.lineStyle( 1, 0x00ff00); 
>                      } else { 
>                          g.lineStyle( 1, lineCol); 
>                      } 
>                      g.moveTo(0,rowInfo[ curRow].y+ 1); 
>                      g.lineTo(width, rowInfo[curRow] .y+1); 
>                  } catch (e:Error) { 
>                      trace(e.getStackTra ce()); 
>                  } 
>                  curRow++; 
>              } 
>              while (rowBGs.numChildren > 0) 
>              { 
>                  rowBGs.removeChildA t(rowBGs. numChildren - 1); 
>              } 
>          }
> ============ ========= ========= ========
> 
> Please let me know if anybody knows about this asap.. Thanks in advance....
> 
> 
> Thanks & Regards,Venkat.
> 
> 
> 
> 
> ____________ _________ _________ __
> From: venkateswarlu naidu contactvenku@ ...
> To: aha...@...; flexcod...@yahoogro ups.com
> Sent: Tue, 15 December, 2009 9:40:03 PM
> Subject: [flexcoders] drawing horizontal line in ADG based on data
> 
> 
> Hi Guys,
> 
> Hope everybody is doing good.
> I have a problem in drawing horizontal line in Advanced datagrid based on 
> some data of the row (ex: data.label=' XXX').
> I tried overriding drawHorizontalLine , it did work but when you start 
> scrolling everything gets messed up.
> 
> Can anybody help me how to solve this?
> 
> Appreciate your help.
> 
> Thanks & Regards,
> Venkat.
> 
> The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. 
> http://in.yahoo. com/
> 
> 
> 
> 
>       The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. 
> http://in.yahoo. com/
>

 


      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. 
http://in.yahoo.com/

Reply via email to