本文介绍如何在 List 控件中选择项时,动态地显示或隐藏对应 DataGrid 的列,实现数据视图的自定义显示。
摘要由CSDN通过智能技术生成
在List中选中一个就会显示相应的 DataGrid 的列
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" horizontalAlign="left" creationComplete="initApp()"> <mx:Script><![CDATA[ import mx.controls.dataGridClasses.DataGridColumn; //import mx.controls.DataGrid; import mx.collections.XMLListCollection; [Bindable] private var _xlcCatalog:XMLListCollection; //the dataProvider for the DG //run by creationComplete public function initApp():void {
_xlcCatalog = new XMLListCollection(xmlCatalog.product); //wrap the XML product nodes in an XMLListCollection lstColumns.selectedItems = new Array(dgHideShow.columns[0]); //set the column list dataProvider to the DataGridColumns }//initApp private function hideShowColumns():void {
var aColumns:Array = dgHideShow.columns; var aSelectedColumns:Array = lstColumns.selectedItems; var dgc:DataGridColumn; var sDataField:String; var sDataFieldCur:String; var bFound:Boolean for (var i:int=0;i<aColumns.length;i++) {
bFound = false dgc = aColumns[i]; sDataField = dgc.dataField; for (var j:int=0;j<aSelectedColumns.length;j++) {
sDataFieldCur = aSelectedColumns[j].dataField; if (sDataFieldCur == sDataField) {
bFound = true; break; } }//for (var j: if (bFound) {
dgc.visible = true; } else {
dgc.visible = false; } }// for (var i: }// ]]></mx:Script> <mx:VBox> <mx:Label text="Multi-Select"/> <mx:Label text="Columns"/> &l