How to know when my itemRenderer is selected

This problem was logged as bug SDK-9846. It didn’t seem that easy for an itemRenderer to know that it was selected so that it can display itself accordingly. However, it is easy for an itemRenderer to know that it’s selected. As mentioned by Alex Harui, in the bug report, here is the simple line that let’s you know:

ListBase(owner).isItemSelected(data)

If you want to change the appearance of your itemRenderer depending on whether it is selected, you should do so using the line above within the updateDisplayList function that you have overridden.

In the following example, the text in the “price” column changes some of its attributes when selected.

Demo: selectExample.swf

Sample Code: selectExample.mxml, MyLabel.as

9 responses

  1. Hi,
    thanks for this example, but unfortunatly I get an error using your code. I use Flex Builder 3 and it throws the following error: TypeError: Error #1034: Typumwandlung fehlgeschlagen: mx.controls.listClasses::ListBaseContentHolder@266860b1 kann nicht in mx.controls.listClasses.ListBase umgewandelt werden.

    Sorry for the german, but it says it can’t covert ListBaseContentHolder to ListBase. Any suggesitions on this?

    Highly apprechiated!

  2. Hey,

    This doesn’t seem to work on Flex 3 … the solution I found was change it a bit to :

    if(owner is ListBase && ListBase(owner).isItemSelected(data)) …

  3. Rather than having the rendered item know about it’s parent, we’ve taken a slightly different approach to solving the problem. If you subclass your list and override the drawItem function, you’ll be able to reference your item and set a selected property on it at that time. Then, all you have to do is put a setter on your rendered item to handle the display changes.

  4. Hi, thanks for sharing this piece of code. However, I have one issue, when I am trying to keep one item selected on creation complete, it is not doing so. I am using a list control and rendering a datagrid in its itemRenderer. I used a function that is setting the selectedIndex of the list but it didnt show up. Again I put an event listener and dispatched an event on creation complete of parentDocument but it doesnt work. Can you help?

  5. How do I change the cell color if Data has changed (it is not a value field ). I want to change color when data is changed in cell.

  6. My question is that how can we access other component tab navigator id from one component to other component. I just try to use this code

    authDetailTabNavigator.selectedIndex=4;
    authDetailTabNavigator is tab navigator’s id of other component.
    But it give error that authDetailTabNavigator is not found in this in this component.

    Any suggestion…

  7. hi,thanks for the post.
    I have one issue,I have a dropdownlist.in the i have data the data like some of are in bold data. if when i am selecting that bold data the dropdown should not be closed.it should pointing the same.
    i have reached some extent means i have checking with open event and indexchange event its works fine with this event but when i am using change event its not working.my problem is is there any way to call in before change i want to call the itemrender lable event.(means i have used customitemrenderer my dropdownlist)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: