开发者

Dynamically Add columns to datagrid in Flex

开发者 https://www.devze.com 2023-04-06 15:36 出处:网络
I am trying to make a datagrid, that wi开发者_Python百科ll dynamically add columns to it based on some condition.

I am trying to make a datagrid, that wi开发者_Python百科ll dynamically add columns to it based on some condition. Now, I am able to add the columns, but I want the newly added column to have button using itemRenderer.

I am unable to achieve this though. Getting this error on line 1

Description Resource Path Location Type 1067: Implicit coercion of a value of type mx.controls:Button to an unrelated type mx.core:IFactory. Demo.mxml /Demo/src line 14 Flex Problem

Can anyone help ?

Here's a code snippet :

private function addDataGridColumn(dataField:String):void {
            var dgc:DataGridColumn = new DataGridColumn();
            dgc.itemRenderer = button1;    // Line 1 
            var cols:Array = dataGrid.columns;
            cols.push(dgc);
            dataGrid.columns = cols;
        }


The itemRenderer and itemEditor properties are of type IFactory. When you set these properties in MXML, the MXML compiler automatically casts the property value to the type ClassFactory, a class that implements the IFactory interface.

When you set these properties in ActionScript, you must explicitly cast the property value to ClassFactory

You might be looking for this, adds buttons to all rows of newly added column.

private function addDataGridColumn(dataField:String):void {
                var dgc:DataGridColumn = new DataGridColumn();
                dgc.itemRenderer = new ClassFactory(Button);
                var cols:Array = dataGrid.columns;
                cols.push(dgc);
                dataGrid.columns = cols;
            }
0

精彩评论

暂无评论...
验证码 换一张
取 消