超级强大的DataGrid组件

12年前
DataGrid 组件允许用户显示和操作多列数据。
当 DataGrid 实例从单击或 Tab 键切换中获得焦点时,您可以使用以下按键来控制它:


以下示例演示数据网格的属性。

从"库"面板中拖动相关组件到舞台(或直接通过 ActionScript 代码创建组件实例),并对实例命名。

在主时间轴中选择第一帧,打开"动作"面板,然后输入以下代码:

my_dg.setColumnNames(["id","name","score"]);  my_dg.addItem({id:0,name:"Clark",score:3135});  my_dg.addItem({id:1,name:"Bruce",score:403});  my_dg.addItem({id:2,name:"Peter",score:25}); 

通过设置 CellRenderer 创建类似 List 的 DataGrid。

首先,创建数据网格的行渲染器 DataGridRowRenderer 类(继承于 ListCellRenderer)。

package {   import flash.text.TextField;   import shinater.swing.DataGrid;   public class DataGridRowRenderer extends ListCellRenderer {    public override function setSize(width:Number, height:Number):void {     _width = width;     _height = height;     repaint();    }    public override function repaint():void {     var dataGrid:DataGrid = DataGrid(getOwner());     var x:Number = textField.x;     for (var i:int = 0,columnCount:uint = dataGrid.getColumnCount(); i<columnCount; i++) {      var txt:TextField;      if (i == 0) {       txt = textField;      } else {       var n:String = "textField" + i;       txt = getChildByName(n) as TextField;       if (txt == null) {        txt = new TextField();        txt.name = n;        addChild(txt);       }       txt.defaultTextFormat = textField.defaultTextFormat;       txt.x = x;       txt.y = textField.y;       txt.height = textField.height;      }      txt.text = getData()[dataGrid.getColumnName(i)];      txt.width = dataGrid.getColumnWidth(i);      x += txt.width;     }     skin.width = _width;     skin.height = _height;     if (focusRectSkin != null) {      focusRectSkin.width = _width;      focusRectSkin.height = _height;     }    }   }  }

同上例,在主时间轴中选择第一帧,打开"动作"面板,然后输入以下代码:

my_dg.setCellRenderer(DataGridRowRenderer);  my_dg.setColumnNames(["id","name","score"]);  my_dg.addItem({id:0,name:"Clark",score:3135});  my_dg.addItem({id:1,name:"Bruce",score:403});  my_dg.addItem({id:2,name:"Peter",score:25});

参考资料来源于:http://原网站已经失效/FlashSwing/Help/DataGrid.html