You can create datagrid column dynamically by using the following method,

//Specify the  column name & description

            var columnName:String = "Sample";
            var columnDescription:String = "Sample";
            var cols:Array;
            var dgc:DataGridColumn = new DataGridColumn(columnName);

            dgc.dataField = columnName;
            dgc.headerText = columnDescription;
            dgc.sortable = true;
            dgc.width = 50;
            cols = dataGrid.columns; // this line is needed if u have
already column for the grid
            cols.push(dgc);
            dataGrid.columns = cols;

Note:

If you want to create multiple column then copy the above code inside of
function and pass column name and description as variable. And don't forget
to assign the existing column     *( cols = dataGrid.columns;)*, otherwise
last column which u added lastly will be shown.

Then set the  dataprovider for the grid,

           var collectionData :ArrayCollection;
           collectionData = new ArrayCollection({sample: "Test"});
           dataGrid.dataProvider = collectionData;

Try it out....




On Wed, May 4, 2011 at 8:19 AM, Gaurav <[email protected]> wrote:

> Hi Friends,
>
> I am trying to add columns in a datagrid dynamically after some button
> click event (or say after application creationComplete). It is not
> showing up the columns.
> Initially I created Datagrid with zero column. It is my requirement to
> generate the columns after analyzing the dataset/dataprovider.
>
> Regards,
> Gaurav
>
> --
> You received this message because you are subscribed to the Google Groups
> "Flex India Community" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/flex_india?hl=en.
>
>


-- 

Regards,

Manikandan.S  <http://www.umoldit.com>
 <http://www.umoldit.com>

-- 
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en.

Reply via email to