flex list with itemRenderer - apache-flex

I have a simple list bounded to an ArrayCollection and an itemRenderer
When I add a new item to the ArrayCollection, I get the event addedToStage: FINE
Trouble is when I remove an item from the ArrayCollection, I never events :
I tried:
remove, removed, removedFromStage and I need to stop a stream when the items is removed:
So HOW can I get an event when an ITEM is REMOVED ?
Thanks

Thing is item renderers are recycled. So when you remove the item from your collection, the item renderer is not destroyed, it's just given another data.
You can add an event listener on the dataChange event or override the set data function.
What are your tring to do exactly?

You should listen to the ArrayCollection events if you want to know if the ArrayCollection instance is changed. But I'm not sure what you are trying to accomplish. If you remove an item from the ArrayCollection then you should know that it is removed. Why or where do you need an event?

Related

Flex:how to disable particular item in combobox?

I have ComboBox With ArrayCollection as DataProvider. Data will come from Databse as ArrayCollection. I'm Adding Item to ArrayCollection "-Select Item-" at 0th index and setting selected index=0 for combobox.
My question is How to disable that(-select Course-) item?
I recommend you to use prompt property of DropDownList or ComboBox for that and combine it with selectedIndex = -1 as initial value.
Worst case an item renderer to show things as disabled. Then simply ignore the click if it has the property disabled. (this implies your list is overloaded with a property like isDisabled.
Mylist.selctedItem.isDisabled

Flex Hero spark component - changing view from within custom itemrenderer

I've made a custom list itemRenderer with 2 buttons and a label. One button deletes the list entry (and thats not the problem) the second button would change the actual view.
Does anyone knows how I can change actual view within the itemrenderer ?
From what I think I understand, you want to change a viewstack or something. What you want to do is bubble an event from the itemRenderer up to a point in the display list where someone will listen and trigger an event handler which then changes the view.
So, in your itemRenderer do
dispatchEvent(new Event('someEventName', true));
And up the display list you need to listen for that even
this.addEventListener('someEventName', someHandlerFunction);
And in that function just switch your view or whatever else you want.

creation complete

Can i use creation complete in item renderers , i have a data grid and i have kept every single cell as an item renderer. is it a good practice to use creation complete here. I fear events might fire up at wrong instances.suggestions are most welcomed.
Use "dataChange" even instead.
More info at Adobe:
http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_7.html
Flex might reuse an instance of the
item renderer or item editor, a reused
instance of an item renderer or item
editor does not redispatch the
creationComplete event. Instead, you
can use the dataChange event with an
item renderer or item editor. Flex
dispatches the dataChange event every
time the data property changes.
The problem with item renderers is that their number depends on the visible area and they are reused in flex.Scrolling issues are a very common problem in datagrids using itemrenderer such as Checkbox,TextInput etc., due to this.So dont use event handler on creationComplete .
There is always a work around :)
creationComplete is a phase in the flex application life cycle.
For more information you can go through the following link:
http://technobytz.com/flex-preinitialize.html

Trigger an itemEditEnd event within the itemEditor

This might be an easy one for you DataGrid experts out there. I following an example for adding rows to a DataGrid dynamically from within a row
http://www.switchonthecode.com/tutorials/adding-dynamic-rows-to-flex-datagrid
My tweak that I am trying to acoomlish, is to have a custom itemEditor that is a form with two TextInputs and an OK button. For the life of me I can't get that button to trigger the DataGrid's itemEditEnd event where I have some processing before I call destroyItemEditor. I tried dispatching the event myself directly but got a strange error in DataGrid's updateDisplayList saying editedItemPosition was null (editedItemPosition.rowIndex). Any ideas?
I figured out the "duh" answer. Basically, within the itemEditor get reference to the DataGrid using listData.owner and then set the DataGrid's editedItemPosition and selectedIndex. This way lets the component worry about cleaning up the itemEditor.
var grid:DataGrid = listData.owner as DataGrid;
grid.editedItemPosition = null;
grid.selectedIndex = -1;
itemEditEnd will be triggered when you click outside the item editor. If you are dispatching it yourself, you need to set the rowIndex property of the event to the appropriate value before dispatching.

Flex Combobox - Edit/Delete an option

I'm using a combo box control and the dataprovider is set as an XML.
After the dataprovider is set, I want to edit the text of the first option and also I need to insert an item in the second position.
How can I do this? Using an ItemRenderer?
Please give your suggestions.
You should edit the dataProvider itself. Make it an ArrayCollection (or something else that implements IList) and your combobox will automatically update as you make changes. Also make sure that the array collection is full of bindable objects.
Changing ArrayCollection is easy. You can just say dataProvider.getItemAt(0).labelProperty = "whatever" -- this assumes you have an object with a property of "labelProperty" and your combobox's labelField is set to it.
To add an item just use dataProvider.addItemAt(item, 1)

Resources