使用ActionScript建立DataGrid, 添加右键, 增加列, 并设定列的ItemRenderer

Categories: Flex; Tagged with: ; @ January 6th, 2009 0:59

很多时候为了获得对组件的灵活控制, 不得不放弃MXML, 直接使用ActionScript.

 
//新建一个DataGrid _dataGrid = new DataGrid(); 
//增加右键 
var menu:NativeMenu = new NativeMenu(); 
var menuItemDelete:NativeMenuItem = new NativeMenuItem("Delete"); 
//监听事件,在右键选定Delete时运行该函数
 menuItemDelete.addEventListener(Event.SELECT, onMenuDeleteClicked); 
//将该menuItem加入到Menu中 
menu.addItem(menuItemDelete);
 _dataGrid.contextMenu = menu; //将菜单加入到DataGrid中 

columnLocale = new DataGridColumn(); //新建一个列 
columnLocale.dataField ="locale";//设定DataGrid中locale列的EditItem;
comboBoxLocaleEditor = new ClassFactory(ComboBox); // D
comboBoxLocaleEditor.properties = {dataProvider : LocalizationItem.localeArray} //设定该EditorItem的属性 
columnLocale.itemEditor = comboBoxLocaleEditor; 

var columnGender:DataGridColumn = new DataGridColumn();
 columnGender.headerText = "Gender""; 
columnGender.dataField = "Gender_"; 
//使用ItemRender 
columnGender.itemRenderer = new ClassFactory(Gender_Label);
 _dataGrid.showHeaders = false; //隐藏DataGrid的Header 
_dataGrid.columns = [columnLocale, columnGender]; //这一个数组,存放DataGrid的Column 

_dataGrid.dataProvider = value; //设定dataProvider 

具体在实际中的使用, 无异于MXML.

<->



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