如何在 DataGrid 中获取 ComboBox 的值 [英] How to get the value of a ComboBox within a DataGrid

查看:27
本文介绍了如何在 DataGrid 中获取 ComboBox 的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然这可能是一个简单的问题,但我花了很长时间想出一个解决方案.

While this may be a simple problem, I'm having a heck of a time coming up with a solution.

我有一个带有 ComboBox 的 DataGrid 作为我的一列的 ItemRenderer.当用户选择一行时,我想获取所选行的 ComboBox 的选定值.

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 ComboBox's selected value for the selected row.

我应该提到 myData 中的 dataField2_Array 属性实际上是一个 Array 是 ComboBox 的 dataProvider.myData 中的每个对象在该 Array 中都可以具有完全不同的值,因此 DataGrid 中每一行中的 ComboBox 可以有完全不同的选项可供选择.

I should have mentioned that the dataField2_Array property in myData is actually an Array is the dataProvider for the ComboBox. Each object in myData could have completely different values in that Array so the ComboBox in each row of the DataGrid could have completely different options to pick from.

有什么建议吗?

一些示例代码:

<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>

推荐答案

<mx:DataGrid ="MyDataGrid">
<mx:columns>
<mx:DataGridColumn headerText="Resource" width="200" itemRenderer="com.myClasses.myGridDropdownRenderer"/>
</mx:columns>
</mx:DataGrid>

这是您的数据网格的 itemRenderer.

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>

这将在您的主应用程序中,它将保存此值.

This will be in your main Application which will be holding this value.

[Bindable] public var whateverStuff:ArrayCollection;

现在,当您的数据发生更改时,它会保存数据.您单击按钮将此值存储在行对象中.

Now when your data is changed, it holds the data. You click on the button store this value in a rows object.

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

当您将值发送回数据库时,连同此行对象一起发送.

When your sending the value back to database, send all along with this rows object.

更新:

在我阅读了您对上一次还击的评论后,我了解到您的每个组合框都有不同的选项.你应该早点提到它.

After i read your comment on the previous riposte, i came to know that each of your combo box has a different options. You should have mentioned it earlier.

当您单击选定的行时,您应该能够收集该行的 ID,这将确保即使您更新其他行的组合框,数据库中也只有该行的 ID 会更新.

When you click on the selected rows, you should able to collect the ID of the row, and this would ensure that only the ID of that row is getting updated in the database regardless even if you update your combo box of other rows.

选择一行后,单击并验证您使用警报或跟踪选择的行 ID,然后通过事件调度程序单独发送该行值.

Once your select a row, click and verify on which row ID you have selected using Alert or trace, then send that rows value alone through an event dispatcher.

这篇关于如何在 DataGrid 中获取 ComboBox 的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆