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)
Related
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
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
Is this possible? I would like to be able to push a text field's value into an array on a button click, then have that array populate a data grid. I'm kind of new to flex and was wondering if someone could point me in a direction or show me how to do this.
Yes, this is very possible. Create an array and assign it as the dataProvider for your DataGrid (Make sure your array is declared to as Bindable). Then append the value of the text field to your array whenever the user clicks the button. The DataGrid should update automatically whenever your bindable array changes. Hope that helps.
I have an itemRenderer for a list where I'm just displaying items and their details respectively. I want to keep the details invisible and have a button,Show Details, in my main mxml file which when clicked would make the details visible.
So, my problem is in the clickHandler how can I access the details property within the itemRenderer from the main mxml?
Thanks in advance for your help
I would have a Boolean on the main which is what the itemRenderer keys off of. Accessing the itemRenderers of a list is not receommended because they are recycled, and operations cannot be guaranteed.
For an explanation see http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html
There are a few ways to approach this.
One is to use a global Singleton object that contains the "ShowDetails" value. Every itemRenderer can access that object and change it's settings. Cairngorm's ModelLocator is one example of a singleton that is commonly used in this way. I believe swiz has something similar. You could also roll your own if needed.
You could try to extend the List class The List keeps itemRenderers in an array, which I believe is protected. You'll have to extend the List, and make this protected array public. Then you'll be able to access the list of itemRenderers and modify properties on them directly.
However, I'm not sure I would recommend either approach. An itemRenderer really should choose what to display based on the data it is displaying; not some global variable. Can you change the objects in your dataProvider and have the itemRenderer update accordingly? It is a third option; although I'm not sure if it is any better, or worse, than the previous two approaches.
You could have a variable in the DataProvider array called 'show' thats set to false. In the itemrenderer bind the visible property of the details component to data.show.
When the show button is pressed, traverse the dataProvider array, and set the 'show' property to true. This will work
Bish
I have a DataGrid which contains a DataGridColumn with a textinput and DataGridColumn with a Button.
The DataGrid is bound to some XML which displays values in the text box.
When the button for a row is clicked I need to get the value out of the text box and save it into the relevant XML node.
My solution was just to pass the id of the row to the button click event then loop over the rows until I find the id then just grab the text box value. Simple.
However the only advice I can find on looping over the rows is via the underlying dataProvider, which is nonsense as the two aren't the same thing.
Is this even possible? or is there a better way?
NOTE I would prefer not re-writing the markup, unless I have to.
Thanks
You are probably using an itemRenderer for your DataGridColumn to show the textBox (aka, TextInput component). I suggest that you dispatch a custom event out of the TextInput itemRenderer when you have a TextInput.dataChange event (or some other TextInput.Event that suits when you are ready to save the value).
http://livedocs.adobe.com/flex/3/langref/mx/controls/TextInput.html
Please remember that you need to bubble this event handling outside of the itemRenderer (e.g., the DataGrid) -- itemRenderers don't handle events well.
Also, one reason that a button to save your TextInput value is not a good idea, is because they are both itemRenderers, and it is hard to communicate between itemRenderers -- it is hard because Adobe deems it unclean code.
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html
Also, this is another solution that changes the dataProvider for a ComboBox (in your case, it's a TextInput instead of ComboBox):
http://www.switchonthecode.com/tutorials/simple-datagrid-item-editor-in-flex
listData.rowIndex from the itemRenderer returns the current row index. You can read it from the click handler as:
private function clickHandler(event:MouseEvent):void
{
var listData:BaseListData = IDropInListItemRenderer(event.target).listData;
var clickedRowIndex:Number = listData.rowIndex;
}