add file icon to datagrid in flex
I'm trying to put some File objects into a DataGrid, but I can't find a开发者_开发问答 way to display the File.icon in there.
So far I have this: (ms[x] is a File)
listData.addItem({
filename:ms[x].nativePath.replace(/.*\\/,""),
path:ms[x].nativePath.replace(/\\[^\\]*$/,"\\"),
icon:ms[x].icon.bitmaps[0]
});
and
<mx:DataGrid x="358" y="0" width="429" height="378" dataProvider="{listData}">
<mx:columns>
<mx:DataGridColumn headerText="Column 1" dataField="filename"/>
<mx:DataGridColumn headerText="Column 2" dataField="icon">
<mx:itemRenderer>
<fx:Component>
<mx:Image width="32" height="32" source="{data}">
</mx:Image>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Column 3" dataField="path"/>
</mx:columns>
</mx:DataGrid>
filename and path are displayed correctly, I just can't get the file icon to show.
How can I do that ?
The source of the image needs to be the path to the file and right now your sending it the whole data object. Assuming data.path
contains the full path including the filename you would type:
<mx:Image width="32" height="32" source="{data.path}">
精彩评论