Resizing a DataGrid instance in Flash using ActionScript 3.0
There are several ways different ways to resize a DataGrid component on the display list. Previous examples have used the width property to resize the component horizontally. You can also resize a DataGrid instance by setting the height or rowCount property, or by calling the setSize() method.
Note: Resizing a component using the width, height, or rowCount properties or the setSize() method causes a resize (ComponentEvent.RESIZE) event to be dispatched.
The following example resizes a data grid using the setSize() method, which is inherited from the UIComponent class (fl.core.UIComponent).
Full code after the jump.
// ActionScript 3.0 import fl.controls.DataGrid; import fl.data.DataProvider; var dp:DataProvider = new DataProvider(); dp.addItem({columnA:"Row 1A", columnB:"Row 1B"}); dp.addItem({columnA:"Row 2A", columnB:"Row 2B"}); dp.addItem({columnA:"Row 3A", columnB:"Row 3B"}); var myDataGrid:DataGrid = new DataGrid(); myDataGrid.addColumn("columnA"); myDataGrid.addColumn("columnB"); myDataGrid.dataProvider = dp; myDataGrid.setSize(200, 200); myDataGrid.move(10, 10); addChild(myDataGrid);
You can also resize a DataGrid component by using the rowCount property. This allows you to set the number of rows that are at least partially visible in the data grid. The following example resizes the data grid instance to match the number of items in the data provider:
Note: The previous example set both the width and rowCount properties. Setting the rowCount property only sets the height of the component, not the width.
Tip: If you want to adjust the height of each row, make sure you set the rowHeight property before setting the rowCount property.
For more information on the Flash/ActionScript 3.0 DataGrid component, see the “Creating, populating, and resizing the DataGrid component” Flash Quick Start on Adobe.com.
