2 Replies Latest reply on Jul 26, 2006 3:46 PM by Josh Johnson

    Conditional Image Outside a DataGrid

    Josh Johnson Level 1
      So Joan was kind enough to help me use data from a DataGrid cell, and conditionally display an image that matched the cell data. That worked great, but now I've got a further issue.

      Completely outside the datacell, I have a list of properties, which show values based on the row selected in the grid (a detail view as it were). Here again I have the same issue, where I need to display 1 of 6 images depending on the value of a variable for the object selected in the DataGrid.

      In the previous example, the solution was to override the set data method, but that won't work in this instance because the item isn't a DataGrid that supports that. Any thoughts on how I should be approaching this?
        • 1. Re: Conditional Image Outside a DataGrid
          peterent Level 2
          I assume that your data used in the DataGrid has a field to indicate the image. Let's say it is called "image". When the row is selected a change event is dispatched (or you can use itemClick). The DataGrid's selectedItem will be the record with the image field in it.

          If you have <mx:Image id="showHere" width="640" height="480" />

          Then in the DataGrid event handler you can do: showHere.source = event.target.selectedItem.image;

          If you do not have <mx:Image> but have your own component, then using data is again a viable way to go:

          <MyImageViewer id="showHere" width="640" height="480" />
          DataGrid event handler: showHere.data = event.target.selectedItem ;

          and MyImageViewer.mxml:

          <mx:Image xmlns:mx=" http://www.adobe.com/2006/mx" source="{data.image}">
          </mx:Image>

          All components have data and you can override the set data function if you need to. Here you don't need to do that.
          • 2. Re: Conditional Image Outside a DataGrid
            Josh Johnson Level 1
            Thanks Peter. I was able to use this and set up an event listener to watch the DataGrid, and then change the image accordingly.