【问题标题】:Dynamically Add columns to datagrid in Flex在 Flex 中动态地将列添加到数据网格
【发布时间】:2011-11-23 03:12:48
【问题描述】:

我正在尝试制作一个数据网格,它将根据某些条件动态地向其中添加列。 现在,我可以添加列,但我希望新添加的列具有使用 itemRenderer 的按钮。

我无法做到这一点。在第 1 行出现此错误

描述资源路径位置类型 1067:隐式强制转换 mx.controls:Button 类型的值到不相关的类型 mx.core:IFactory。 Demo.mxml /Demo/src 第 14 行 Flex 问题

谁能帮忙?

这是一个代码 sn-p:

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;
        }

【问题讨论】:

  • 可以展示button1的声明和初始化吗?

标签: flash apache-flex actionscript-3 datagrid


【解决方案1】:

itemRendereritemEditor 属性的类型为 IFactory。当您在 MXML 中设置这些属性时,MXML 编译器会自动将属性值转换为 ClassFactory 类型,这是一个实现 IFactory 接口的类。

ActionScript 中设置这些属性时,必须将属性值显式转换为ClassFactory

您可能正在寻找这个,将按钮添加到新添加列的所有行。

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;
            }

【讨论】:

  • 我打算发布相同的答案,所以是的,就是这样!
猜你喜欢
  • 2016-04-21
  • 1970-01-01
  • 2015-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-23
  • 2015-04-28
相关资源
最近更新 更多