How to get ComboBox value in DataGrid

While this may be a simple problem, I have the time to solve it.

I have a DataGrid with a ComboBox as an ItemRenderer for one of my columns. When the user selects a row, I want to get the selected ComboBox value for the selected row.

EDIT: I should have mentioned that the dataField2_Array property in myData is actually an array - dataProvider for ComboBox. Each object in myData can have completely different values ​​in this array, so the ComboBox in each row of the DataGrid can have completely different choices.

Any suggestions?

Code example:

<mx:DataGrid id="myGrid"
  dataProvider="{myData}">
    <mx:columns>
      <mx:DataGridColumn headerText="Column 1" dataField="dataField1" />
      <mx:DataGridColumn headerText="Column 2" dataField="dataField2_Array">
        <mx:itemRenderer>
          <mx:Component>
            <mx:HBox paddingLeft="5">
              <mx:ComboBox id="myComboBox" dataProvider="{data.dataField2_Array}" />
            </mx:HBox>
          </mx:Component>
        </mx:itemRenderer>
      </mx:DataGridColumn>
    </mx:columns>
</mx:DataGrid>
0
source share
2 answers
<mx:DataGrid ="MyDataGrid">
<mx:columns>
<mx:DataGridColumn headerText="Resource" width="200" itemRenderer="com.myClasses.myGridDropdownRenderer"/>
</mx:columns>
</mx:DataGrid>

Here is your itemRenderer for your datagrid.

<?xml version="1.0" encoding="utf-8"?>
<mx:ComboBox prompt="Please select a Rating" change="stuffChanged()" dataProvider="{data.dataField2_Array}"
     xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
        <![CDATA[
            import flash.events.Event;
            import mx.controls.Alert;
            import mx.core.Application;
            import mx.collections.ArrayCollection;



            override public function set data( value:Object ) : void {
                super.data = value;

            }



           public function stuffChanged():void{
               var myListData:DataGridListData = DataGridListData(listData);
               var r:int=myListData.rowIndex;
               var c:int=myListData.columnIndex;
              //Application.application.whateverStuff[r+1][c]=this.value;
               Application.application.whateverStuff[r+1][c]=
              this.selectedItem.data;
              }



        ]]>
    </mx:Script>

</mx:ComboBox>

, .

[Bindable] public var whateverStuff:ArrayCollection;

, , . , rows.

[Bindable] public var rows:Object = new Object();
rows=Application.application.whateverStuff; 

, .

Update:

, , , . .

, , , , ,

, Alert trace, .

+2

myGrid_click click DataGrid:

<mx:DataGrid id="myGrid" dataProvider="{myData}" click="myGrid_click(event)" >

selectedIndex , dataProvider (, MyObjects, dataField2 MyObjects):

public function myGrid_click(event:MouseEvent):void {
    var index:int = myGrid.selectedIndex;
    var obj:MyObject = myData[index];
    var value:String = obj.dataField2;
}

, , (dataField2_Array?), for dataField2_Array, (actualValue ) (selectedRowComboBoxValue):

public function myGrid_click(event:MouseEvent):void {
    var index:int = myGrid.selectedIndex;
    var obj:MyObject = myData[index];
    var value:int = obj.dataField2;

    for (var i:int = 0; i < dataField2_Array.length; i++) {
        if (value == dataField2_Array[index].id) {
            selectedRowComboBoxValue = dataField2_Array.actualValue;
            break;
        }
    }
}
+1

Source: https://habr.com/ru/post/1786814/


All Articles