Here’s my problem. I have an mx:Image within an mx:DataGrid column. If I do not specifically set the width and height of the image, when the image loads into the grid, only a portion of the image is being displayed.
Recreation Steps:
- Create new Flex Project (Desktop)
- Configure project to use Halo Theme.
-
Add the following code in their respective locations
*Note: Make sure the creationComplete event for the windowedApplication is assigned. Also may need some tweaking for any import statements, etc. Sorry.* -
This is a quick example of the issue I’m having. When you launch the program, you will see a portion of the image. When you click Rebind, the full image will occur.
I’m trying to get the full image to be displayed on the first bind, not the second without setting the dimensions in the MXML. I have not been successful in having the full image display via ActionScript without some sort of user interaction to occur.
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
BindData();
}
private function BindData():void
{
var objOrderItem:Object = new Object();
var items:ArrayCollection = new ArrayCollection(new Array(objOrderItem));
dgMain.dataProvider = new ArrayCollection(items.source);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:VBox width="100%">
<mx:Button label="Rebind" click="BindData()" />
<mx:DataGrid id="dgMain" resizableColumns="false" draggableColumns="false"
sortableColumns="false" rowCount="1">
<mx:columns>
<mx:DataGridColumn headerText="Thumb" sortable="false" width="60">
<mx:itemRenderer>
<fx:Component>
<mx:HBox horizontalGap="0" verticalScrollPolicy="off" horizontalScrollPolicy="off" width="100%">
<mx:Image source="https://encrypted-tbn1.google.com/images?q=tbn:ANd9GcTTuc9n_oweh-dv4LUljzh0Lxzn1AvZchODUoSAeGePaDwPqUuw"
width="60" maintainAspectRatio="true" />
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<mx:Label text="Text After Grid" />
</mx:VBox>
Thanks in advance!
Problem Solved
Hello everyone, I was able to solve my problem by adjusting the row height of the DataGrid where my data is being bound to by checking the row height to see if it’s less than the image’s height. Here’s how I did it:
I attached a listener for the image’s complete event. The listener then fires a function that checks the DataGrid’s rowHeight to see if it’s less than the image’s content’s height. If it is, it updates the rowHeight to the image’s content’s height.
I just was not successful using any of the methods suggested here, as well as any other methods I attempted to use.
Full code example below:
Please keep in mind, this is a quick, and simple implementation of the fix. And more elaborate implementation, IE the one I used in my project, works just as well.