header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
abhishek
Points:0
Posts:0

5/11/2010 4:27:31 AM

Title: how to change background color of specific rows in datagrid in flex


hey frnds,
how to change background color of specific rows in datagrid in flex
like if i'm clicking on button then i want to change bckground color of 1st, 4rth row of datagrid.
thx in advanced,
:)



1
Inder
Points: 2880
Posts:0
5/11/2010 6:30:39 AM



first you need to extend the DataGrid class. below is the code of extended class.

//class dataGridRowBackground.as
package
{
	import flash.display.Sprite;
	import mx.controls.DataGrid;
	public class dataGridRowBackground extends DataGrid
	{
		public function dataGridRowBackground()
		{
			super();
		}
		public function setRowBackgroundColor(rowIndex:Number,color:uint):void{
			var rowBGs:Sprite=Sprite(listContent.getChildByName("rowBGs"));
			drawRowBackground(rowBGs,rowIndex,listContent.rowInfo[rowIndex].y,listContent.rowInfo[rowIndex].height,color,null);
		}
	}
}


you can set color in actionscript using setRowBackgroundColor function :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
<mx:Script>
	<![CDATA[
		import mx.controls.dataGridClasses.DataGridColumn;
		protected function button4_clickHandler(event:MouseEvent):void
		{
			dataGrid.setRowBackgroundColor(3,0xcccccc);
		}
	]]>
</mx:Script>
<mx:ArrayCollection id="arrColl">
	<mx:source>
		<mx:Array>
			<mx:Object name="SUV" value="Automobile" />
			<mx:Object name="Motorcycle" value="Automobile" />
			<mx:Object name="Cycle" value="Automobile" />
			<mx:Object name="Car" value="Automobile" />
			<mx:Object name="Bus" value="Automobile" />
			<mx:Object name="Jeep" value="Automobile" />
			<mx:Object name="Truck" value="Automobile" />
		</mx:Array>
	</mx:source>
</mx:ArrayCollection>
	<local:dataGridRowBackground id="dataGrid" dataProvider="{arrColl}" verticalScrollPolicy="on">
	</local:dataGridRowBackground>
		<mx:Button label="Set background color of Row" click="button4_clickHandler(event)"/>
</mx:Application>


2
abhishek
Points: 0
Posts:0
5/11/2010 11:59:44 PM



thx frnd,
its really nice example ,
:)


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 5+2 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions