setting dynamically rowCount property in DataGrid control of flex.

January 22, 2008

Usually we use rowCount property in the DataGrid Tag itself and it specifies the number of rows in the DataGrid.Example is show below..

<mx:DataGrid showHeaders=”false” id=”mydg” x=”80″ y=”52″ useHandCursor=”true” rowCount=”5″>
<mx:columns>
<mx:DataGridColumn headerText=”Name”
dataField=”name”/>
<mx:DataGridColumn headerText=”Age” dataField=”age”/>

</mx:columns>
</mx:DataGrid>

This specifies that the DataGrid rows are 5.

But what if i want to specify this value of the property dynamically ,i.e which depends on the number of rows received from the DB or ArrayCollection, then you can use the following two lines of code..

mydg.rowCount = mydp.length;

where mydp->ArrayCollection.

and iam setting the rowCount to the lenght of ArrayCollection.

So setting the rowCount of the DG dynamically ,simple and small but very usefull..

rowCount=2

This snapshot shows that the rowCount=2 which is the length of my ArrayCollection..


Pass Multiple Parameters to functions in flex.

January 22, 2008

Any number of parameters can be passed to the functions and here iam passing using by defining a function with three parameters init.Like below..

<mx:Button id=”btnone” label=”one” click=”passpara(’one’,'two’,'three’)” x=”386″ y=”209″/>

so here on click of this button the function is called and three parameters are passed toit.and iam receiving the values with three srtings defined..

<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function passpara(one:String,two:String,three:String):void
{
Alert.show(""+one+two+three," ");
}
]]>
</mx:Script>

The above alert displays the values of three strings..