Formatting the size column on the FileSystemDataGrid control in Adobe AIR
The following example shows how you can format the size column to display bytes or kilobytes in an Adobe AIR FileSystemDataGrid control by setting the sizeDisplayMode
property to one of the static constants in the FileSystemSizeDisplayMode class.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?> <!-- http://airexamples.com/2008/12/26/formatting-the-size-column-on-the-filesystemdatagrid-control-in-adobe-air/ --> <mx:WindowedApplication name="FileSystemDataGrid_sizeDisplayMode_test" xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" showStatusBar="false"> <mx:ApplicationControlBar dock="true"> <mx:Form styleName="plain"> <mx:FormItem label="sizeDisplayMode:"> <mx:ComboBox id="comboBox" dataProvider="[bytes,kilobytes]" selectedIndex="1" /> </mx:FormItem> </mx:Form> </mx:ApplicationControlBar> <mx:FileSystemDataGrid id="dataGrid" directory="{File.documentsDirectory}" sizeDisplayMode="{comboBox.selectedItem}" horizontalScrollPolicy="off" verticalScrollPolicy="on" width="100%" rowCount="12" /> </mx:WindowedApplication>
You can also set the sizeDisplayMode
property using ActionScript, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?> <!-- http://airexamples.com/2008/12/26/formatting-the-size-column-on-the-filesystemdatagrid-control-in-adobe-air/ --> <mx:WindowedApplication name="FileSystemDataGrid_sizeDisplayMode_test" xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" showStatusBar="false"> <mx:Script> <![CDATA[ import mx.events.ListEvent; private function comboBox_change(evt:ListEvent):void { dataGrid.sizeDisplayMode = comboBox.selectedItem.toString(); } ]]> </mx:Script> <mx:ApplicationControlBar dock="true"> <mx:Form styleName="plain"> <mx:FormItem label="sizeDisplayMode:"> <mx:ComboBox id="comboBox" dataProvider="[bytes,kilobytes]" selectedIndex="1" change="comboBox_change(event);" /> </mx:FormItem> </mx:Form> </mx:ApplicationControlBar> <mx:FileSystemDataGrid id="dataGrid" directory="{File.documentsDirectory}" sizeDisplayMode="{comboBox.selectedItem}" horizontalScrollPolicy="off" verticalScrollPolicy="on" width="100%" rowCount="12" /> </mx:WindowedApplication>
Due to popular demand, here is the “same” example in a more ActionScript friendly format:
<?xml version="1.0" encoding="utf-8"?> <!-- http://airexamples.com/2008/12/26/formatting-the-size-column-on-the-filesystemdatagrid-control-in-adobe-air/ --> <mx:WindowedApplication name="FileSystemDataGrid_sizeDisplayMode_test" xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" showStatusBar="false" initialize="init();"> <mx:Script> <![CDATA[ import mx.containers.ApplicationControlBar; import mx.containers.Form; import mx.containers.FormItem; import mx.controls.FileSystemSizeDisplayMode; import mx.controls.ComboBox; import mx.controls.FileSystemDataGrid; import mx.core.ScrollPolicy; import mx.events.ListEvent; private var comboBox:ComboBox; private var dataGrid:FileSystemDataGrid; private function init():void { var arr:Array = []; arr.push(FileSystemSizeDisplayMode.BYTES); arr.push(FileSystemSizeDisplayMode.KILOBYTES); comboBox = new ComboBox(); comboBox.dataProvider = arr; comboBox.selectedIndex = 1; comboBox.addEventListener(ListEvent.CHANGE, comboBox_change); var formItem:FormItem = new FormItem(); formItem.label = "sizeDisplayMode:"; formItem.addChild(comboBox); var form:Form = new Form(); form.styleName = "plain"; form.addChild(formItem); var appControlBar:ApplicationControlBar = new ApplicationControlBar(); appControlBar.dock = true; appControlBar.addChild(form); addChildAt(appControlBar, 0); dataGrid = new FileSystemDataGrid(); dataGrid.directory = File.documentsDirectory; dataGrid.horizontalScrollPolicy = ScrollPolicy.OFF; dataGrid.verticalScrollPolicy = ScrollPolicy.ON; dataGrid.percentWidth = 100; dataGrid.rowCount = 12; addChild(dataGrid); } private function comboBox_change(evt:ListEvent):void { dataGrid.sizeDisplayMode = comboBox.selectedItem.toString(); } ]]> </mx:Script> </mx:WindowedApplication>
- Share this:
- http://get.adobe.com/air/
- Platform ActionScript Language Reference
Recent Posts
- Detecting the number of screens on a users system in Adobe AIR
- Opening a new NativeWindow in Adobe AIR
- Detecting the line-ending character sequence used by the host operating system in Adobe AIR
- Displaying a custom title bar icon in a WindowedApplication container in Adobe AIR
- Setting a custom text style on the status bar on a WindowedApplication container in Adobe AIR
- Keeping a WindowedApplication on top of other windows in Adobe AIR
- Specifying whether a new Window is focused in Adobe AIR
- Opening a new Window in Adobe AIR
- Setting the file size display mode in the Flex FileSystemDataGrid control in Adobe AIR
- Sorting the FileSystemDataGrid control by date in Adobe AIR
Archives
- March 2010 (10)
- February 2009 (3)
- January 2009 (6)
- December 2008 (44)