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="onCreationComplete()"> <mx:Script> <![CDATA[ import mx.collections.SortField; import mx.collections.Sort; import mx.collections.IHierarchicalCollectionView; [Bindable] private var myDP:Array = [ {Office:"Atlanta",Month:"Oct. 2009",Sales:"2000",Rejections:"102",SortDate:new Date('10/1/2009')}, {Office:"Atlanta",Month:"Sept. 2009",Sales:"2000",Rejections:"102",SortDate:new Date('9/1/2009')}, {Office:"Atlanta",Month:"Aug. 2009",Sales:"1000",Rejections:"102",SortDate:new Date('8/1/2009')}, {Office:"Atlanta",Month:"Jul. 2009",Sales:"2000",Rejections:"102",SortDate:new Date('7/1/2009')}, {Office:"Atlanta",Month:"Jun. 2009",Sales:"2000",Rejections:"102",SortDate:new Date('6/1/2009')}, {Office:"Atlanta",Month:"May 2009",Sales:"2000",Rejections:"102",SortDate:new Date('5/1/2009')}, {Office:"Dallas",Month:"Oct. 2009",Sales:"2000",Rejections:"102",SortDate:new Date('10/1/2009')}, {Office:"Dallas",Month:"Sept. 2009",Sales:"1000",Rejections:"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")]; IHierarchicalCollectionView(dg.dataProvider).sort = sort; IHierarchicalCollectionView(dg.dataProvider).refresh(); } ]]> </mx:Script> <mx:AdvancedDataGrid id="dg" height="80%" width="80%" textAlign="center"> <mx:dataProvider> <mx:GroupingCollection id="gc" source="{myDP}"> <mx:Grouping> <mx:GroupingField name="Office"/> </mx:Grouping> </mx:GroupingCollection> </mx:dataProvider> <mx:columns> <mx:AdvancedDataGridColumn dataField="Month" textAlign="left"/> <mx:AdvancedDataGridColumn dataField="Sales" textAlign="left" itemRenderer="BGRenderer"/> <mx:AdvancedDataGridColumn dataField="Rejections" textAlign="left" itemRenderer="BGRenderer"/> </mx:columns> </mx:AdvancedDataGrid> </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[DataGridListData(listData).dataField]); } } override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth, 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 [email protected], venkateswarlu naidu <contactve...@...> 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(indexToItemRenderer(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.drawRowBackgrounds(); > > var rowBGs:Sprite = > Sprite(listContent.getChildByName("rowBGs")); > var lineCol:uint = getStyle("horizontalGridLineColor"); > > 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.getStackTrace()); > } > curRow++; > } > while (rowBGs.numChildren > 0) > { > rowBGs.removeChildAt(rowBGs.numChildren - 1); > } > } > ====================================== > > Please let me know if anybody knows about this asap.. Thanks in advance.... > > > Thanks & Regards,Venkat. > > > > > ________________________________ > From: venkateswarlu naidu contactve...@... > To: aha...@...; [email protected] > 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/ >

