setting dynamically rowCount property in DataGrid control of flex.

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:DataGridColumn headerText=”Name”
<mx:DataGridColumn headerText=”Age” dataField=”age”/>


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..


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


5 Responses to setting dynamically rowCount property in DataGrid control of flex.

  1. Milo says:


    Could you be so kind as to post the sourcecode.
    I’m somewhat new to flex and cannot see where you add the:

    mydg.rowCount = mydp.length;




  2. […] actual post is here and this is the code example of that post.As the viewer […]

  3. kumargandhi says:

    Hi ,
    I made a post on that with code you can refer that and its made on 23/July/2008
    Comments are welcome.

  4. Waqas says:

    Wat if the data is dynamically imported in the datagrid from mysql , how can i use mydp.length ? As i cant define dataprovider id while importing content in datagrid.

  5. kumargandhi says:

    Hi ,
    Thats a good question and the answer is simple.
    First import the Data into an ArrayCollection and then you assign that to the DataGrid[this can be the dataprovider or specifying the length.] these can be done on result of the HttpService. There are posts on Reading data into ArrayColl from a HttpService can refer that.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: