[Flex]DataGrid使用ActionScript增加列 Use AS Add DataGrid Column

Categories: Flex; Tagged with: ; @ October 9th, 2008 1:49

今天开始彻底从MXML迁移到ActionScript.在使用DataGrid时发现不会增加列.
于是查看DataGrid源代码,在1070行附近发现以下代码:

    override public function get columns():Array
    {
        return _columns.slice(0);
    }

    override public function set columns(value:Array):void
    {
       …
    }

这个意思就时应该有类似代码增加其column:

datagrid.columns = [columnsArray]

于是新建两个columns:

	 	var columnLocale:DataGridColumn = new DataGridColumn();
	 	columnLocale.headerText = "Locale";
	 	columnLocale.dataField = "locale";
	 	
	 	var columnContent:DataGridColumn = new DataGridColumn();
	 	columnContent.headerText = "Content";
	 	columnContent.dataField = "content";

	 	_datagrid.columns = [columnLocale,columnContent];

问题解决:

image

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.