I works with Flex 4.5 and I like to create a custom dropdownlist. Indeed, I’d like to show in each line on my dropdownlist a label and a delete button.
The goal is to delete the line on click to delete button.
This look like simple, but I don’t found how to do that.
Thanks for helping
You have to jump through a few hoops for this one because DropDownList prevents any
MouseEvent.CLICKfrom an object inside an ItemRenderer from being fired.First things first: you will need a custom event for this to work. One that carries your item or at least its index. e.g.:
Then you create a custom ItemRenderer with a ‘delete’ Button that will dispatch this event.
Important here is that you catch the MOUSE_DOWN event of the Button, since its CLICK event doesn’t fire (as mentioned before). The
ownerproperty of the ItemRenderer refers to the List it is a child of.Now the last piece of the puzzle. Here’s your DropDownList with custom ItemRenderer:
And here’s how you listen for that custom event and remove the selected item:
Because we caught the MOUSE_DOWN instead of CLICK the
myDropDownList.selectedIndexproperty will still be at the previously selected item (or -1 if none was selected). This is why we needed the custom event, because there was no other way of knowing which is the item you want to remove.