Hi Alex,
There was a mistake in posting the code. However I am not using editorDataField
anymore. In the dataGrid my column is defined as given below and it is using
combobox component defined below the column code. It is working fine but I have
few questions/requirements.
a) I have four columns in the dataGrid with Yes/No choice so I want to make it
generic(library component) for my Application. In my component I need to
provide field name "value.gl" / dg.dataProvider[dg.selectedIndex].gl to make it
work. How can I avoid it?
b) As you can see it is an mxml component based on VBox. Is it ok or should I
write an AS component?
c) I checked your Blog 'Thinking About Item Renderers' which example closely
match my requirement?
Thanks in advance
Arshad
<mx:DataGridColumn id="c7" width="70" textAlign="center" headerText="G/L"
dataField="gl"
editable="false"
itemRenderer="net.forms.itemRender.yesNoComboBoxGl" />
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
implements="mx.controls.listClasses.IDropInListItemRenderer,mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import mx.controls.DataGrid;
import mx.events.ListEvent;
import mx.controls.listClasses.ListData;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.controls.dataGridClasses.DataGridItemRenderer
import mx.events.FlexEvent;
private var _listData:DataGridListData;
[Bindable]
public var cmbValue:Object;
override public function get data():Object {
return super.data;
}
override public function set data(value:Object):void {
super.data = value;
cbo.data=value[_listData.dataField];
if(value.gl =="Y"){
cbo.selectedItem="Yes"
}
else if(value.gl =="N"){
cbo.selectedItem="No"
}
//trace("---->"+value.stringValue)
}
public function get listData():BaseListData
{
return _listData;
}
public function set listData(value:BaseListData):void
{
_listData = DataGridListData(value);
}
private function changeReference() : void {
if (cbo.value == "Yes"){
cmbValue = "Y";
}
else if (cbo.value == "No"){
cmbValue = "N";
}
}
private function onChange(ev:ListEvent):void{
var dg:DataGrid = listData.owner as DataGrid;
var glVal:String;
if (cbo.selectedItem == "Yes"){
glVal = "Y";
}
else if (cbo.selectedItem == "No"){
glVal = "N";
}
dg.dataProvider[dg.selectedIndex].gl = glVal;
}
]]>
</mx:Script>
<mx:Binding destination="cmbValue" source="cbo.value"/>
<mx:ComboBox id="cbo" editable="true" width="100%" change="onChange(event)">
<mx:dataProvider>
<mx:String>Yes</mx:String>
<mx:String>No</mx:String>
</mx:dataProvider>
</mx:ComboBox>
</mx:VBox>
--- In [email protected], Alex Harui <aha...@...> wrote:
>
> I assume your editorDataField is really cmbValue.
>
> I don't know what your data looks like, but you probably don't want to use
> Binding in the renderer. When the data is set, you want to set cmbValue to
> whatever value is currently in the dataField for that data item. Then only
> change it when the combobox sends out a change event.
>
>
> On 2/24/10 11:41 AM, "md_ars" <mdar...@...> wrote:
>
>
>
>
>
>
> Hello,
>
> I have following piece of code from main mxml and below that I have
> component code for Combobox. I am using label function to decode values as
> Yes/No when populating Data Grid from the database. It wipe the value from
> the cell once I click on the combobox and don't select values from it. I used
> prompt in combobox which works to avoid blank but it change the values to
> prompt.
>
> I tried many examples but didn't work for me. Please help. Also I want to use
> Item Renderer instead if Item Editor.
>
> Thanks
> Arshad
>
> main.mxml
> ---------------------
> [Bindable] private var queryData:ArrayCollection = new ArrayCollection();
> ------
> ------
> <mx:DataGrid id="dgGrid" width="644" dataProvider="{queryData}" height="270"
> editable="true" >
> ------
> -----
> <mx:DataGridColumn width="175" textAlign="center"
> headerText="Tax" sortable="false" dataField="tax"
> labelFunction="taxLabel"
> editable="true" editorDataField="value" itemEditor="yesNoComboBox">
> </mx:DataGridColumn>
>
> ---------------------------------yesNoComboBox ----------
> <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
> implements="mx.controls.listClasses.IDropInListItemRenderer,mx.managers.IFocusManagerComponent">
>
> <mx:Script>
> <![CDATA[
> import mx.controls.listClasses.ListData;
> import mx.controls.dataGridClasses.DataGridListData;
> import mx.controls.listClasses.BaseListData;
> import mx.controls.dataGridClasses.DataGridItemRenderer
> import mx.events.FlexEvent;
>
> private var _listData:DataGridListData;
>
> [Bindable]
> public var cmbValue:Object;
>
> override public function get data():Object {
> return super.data;
> }
>
> override public function set data(value:Object):void {
> cbo.data=value[_listData.dataField];
> cbo.selectedItem= value[_listData.dataField];
> trace("---->"+cmbValue)
> }
> public function get listData():BaseListData
> {
> return _listData;
> }
>
> public function set listData(value:BaseListData):void
> {
> _listData = DataGridListData(value);
> }
>
> ]]>
> </mx:Script>
> <mx:Binding destination="cmbValue" source="cbo.value"/>
>
> <mx:ComboBox id="cbo" editable="true" width="100%" >
> <mx:dataProvider>
> <mx:String>Yes</mx:String>
> <mx:String>No</mx:String>
> </mx:dataProvider>
> </mx:ComboBox>
> </mx:VBox>
>
>
>
>
>
>
> --
> Alex Harui
> Flex SDK Team
> Adobe System, Inc.
> http://blogs.adobe.com/aharui
>