Flex ComboBox user choice reset - apache-flex

To be more descriptive here's a live example:
http://interklub.biz/CTPonLine.html
In last column there's a ComboBox with some values.
When user choose an option in ComboBox from first row and then scroll down the first choice disapears (comes back to default state).
There's something more strange, earlier I've tried to apply a one more ComboBox in additional column, with highly dynamic values (completly different for different rows), but with after same action (scroll down and then scroll down) values dataProviders from different ComboBox were switch.

It looks like you're not initializing your item renderer properly--when the renderer is reused, it's keeping its old value rather than updating from your data.
You should be able to resolve this by doing one of the following:
binding the item renderer's selectedValue to some property of its data element
overriding set data() to update the control for the current data
acting on the dataChange event and updating there
See Adobe's Working with Item Renderers for more.

Related

Flex: Combobox creating dropdown with less values

I have an object that inherits from combobox. This is done so I can use a custom framework for creation and value setting and uses a 'id' / 'description' set for the dataprovider. When I set the value, i set the 'id' and the custom object looks through the dataprovider to find the matching id to find the index. When setting the value, I don't know the 'dscription', that is what the row source is for.
My problem is in that I need to display 'old' values when I first set the value through code, but I don't want to allow the user to see the 'old' value in the dropdown and allow them to select it.
Now, I've been trying to chase down the best way to do this. I'm assuming I need to either interrupt the creation of the dropdown dataprovider and populate it with a smaller list(using my own 'hideFromDropdown' property) or find out if there is a way to add a property to my dataprovider that causes the item to not be rendered by the dropdown. Perhaps eich 'item' in the dropdown has a visible property?
I was able to trace down to the combobox.getDropdown method, which creates a new dropdown from the dropdownfacrory. Unfortunatly, this is private so I can't override it to pass a partial rowsource. Now, all the dropdownfacory seems to do is return a basic list. Unfortunately I keep getting lost tracking down to find the place in the list or listbase objects where the individual item in the dataprovider gets rendered(or not). I believe I have traced to listContent:ListBaseContentHolder in ListBase which contains the data, but am constantly getting lost in the ambiguities.
I am using Flex SDK 3.6A in Adobe Flex Builder 3(built on the Eclipse engine)
You can use filterfunction on the dataProvider like arrayList/arraycollection. Checkout the example here
http://kirill-poletaev.blogspot.com/2011/07/arraycollection-in-flex-part-4.html

What's the best practice for generating spark radio buttons?

I have a list of radio buttons, which I want to be able to both set the value of programmatically and for the user to set the value of manually.
I have a small list of data items which I want to display as options in a list of radio buttons. The objects are stored in a model object, as is the currently selected item. The currently selected item is bound to the radiobutton group. The radio buttons are generated using a spark list.
I am having a problem setting the list programatically - whenever I set the current value on the radiobutton group to the first value in the list, all of the radio buttons are cleared, where the first one should be selected. I when checking in the debugger, I found the likely reason - there are two radiobuttons in the group that point to the same value, one of which isn't showing. My best guess is that the list control has created an extra item renderer which it is holding on to in case it needs to scroll the list.
Is there a way to create radioButtons based on an ArrayCollection without using a list? Failing that, is it possible to prevent the list from generating the extra item?
Use a DataGroup with a dataProvider (an ArrayList of objects holding data) with a custom item renderer that creates the radiobutton that you need. Add proper bindings of the data object to the radiobutton (maybe even do 2 way binding for quick saving).
In the end, I gave spark best practices the finger and used a repeater, which created the correct number of radioButtons with no extras. It may be slow, but slow iteration over a set of less than ten items is O(I don't care).

What the best way to coordinate loading initial values in syncronized Combo-Boxes & List Box

Environment: Flex/As3/Cairgorm/composite component.
I have two comboboxes and two datagrids such that the selection of combobox 1, inserts data into combobox two and the fist datagrid. The selection of combobox 2 inserts data into datagrid 2.
I have setup the change event so that the user selection on each of the combo boxes do the right thing. The problem is that on the initial load of the comboboxes, the change event does not fire and subsequent synchronization data loading does not happen.
Is there an event for getting the itemselected (1st item) after the combobox is initialized?
I found my own answer. Using the updateComplete event on each of the comboboxes did the trick.
[EDIT]
It turns out that updateComplete did not work as expected. What I really needed is the dataChange event. However, it appears that this event does not fire for comboboxes even though it is listed as a valid FlexEvent for this component.
I tried a number of other events (valueCommit, creationComplete, initialize) but all of these fire multiple times, overlap with change, and are not useful for this usecase.
In the end, I created a gludge of a chain of calls for the initialize path and change path.
If anyone else has a better way, I'd be very interested.

Flex Drag and Drop

I am creating an application that will allow users to model configuration information by allowing them to Drag and Drop objects from a Flex Tree into a DataGrid.
I know that both the Tree and DataGrid both support Drag and Drop quite well.
My problem is that I want users to drop items from the Tree into a particular Datagrid cell. I think standard drop events into the Datagrid try to fill the whole datagrid row by default. This is not what I want, I want to drop components into a cell only.
I was thinking that each time an object is dropped onto the datagrid you would have to:
- Get the cell location (x,y) the object was dropped into
- Get all the existing cell objects and rebuild that datagrid row from scratch(dynamically) adding the new dropped object to the row in its correct position. Thus giving the illusion that you can drop into a cell - its a bit of a fudge but I think it could work :)
Any feedback would be great.
Thanks in advance
Mike
Turn drag and drop off for the datagrid.
Write a custom renderer which listens to itself for the DragEnter / DragDrop events. In the handler for the drop event, add the item(s) to the data (at the variable referenced by that column).
If your renderer is bound to the item, it will now update.
((Note that isn't best practice, you'd want to dispatch an event containing the renderer's data item, the variable it was representing and the item(s) dropped, and then manipulate the dataprovider outside of the renderer))

ItemRenderer Vs ItemEditor

What is the Difference between ItemRenderer and ItemEditor?
And When ItemRenderer is initializing and loading?
Regards,
Ravi
ItemRenderer is for configuring how something will look in a list control (i.e. a Picture + text might be a use case for an ItemRenderer). Thus "Render", how it will display (read-only).
ItemEditor is used when you want to override how the user might change the value in the list (assuming that you've set all the requisite editable properties on the controls in question to allow edits). A good example could be a date column. Perhaps you want a DataGrid to show a date as 12/28/2009 in the list, but when the user clicks on it, they get a DateChooser control to set a new date.

Resources