检索FlexGrid项

时间:2010-02-02 11:30:21

标签: flex datagrid

我有以下xml

  <?xml version="1.0" encoding="UTF-8" ?> 
  <Users>
    <User>
      <ID>SMSUser(63)</ID> 
      <Email>a@example.com</Email> 
    </User>
    <User>
      <ID>SMSUser(64)</ID> 
      <Email>test@example.com</Email> 
    </User>
  </Users>

上面是与数据网格绑定,如下所示

<mx:Script>
    <![CDATA[
        import mx.rpc.events.FaultEvent;
        import mx.collections.ArrayCollection;      
        import mx.controls.Alert;
        import mx.rpc.events.ResultEvent;       

        [Bindable]
        private var xmlData:ArrayCollection;

        private function resulthandler(e:ResultEvent):void
        {
            xmlData = e.result.Users.User;      
        }
        private function faulthandler(e:FaultEvent):void
        {
            Alert.show("Error");
        }


    ]]>
</mx:Script>


  <mx:HTTPService id="listData" result="resulthandler(event)" 
   fault="faulthandler(event)" resultFormat="object" 
    showBusyCursor="true" method="GET"> 
  </mx:HTTPService>        

    <mx:DataGrid id="dg" dataProvider="{xmlData}" >
        <mx:columns>
          <mx:DataGridColumn dataField="ID" headerText="ID" /> 
          <mx:DataGridColumn dataField="Email" headerText="Email" />      
        </mx:columns>                  
    </mx:DataGrid>

当用户选择网格中的任何项目时,如何在文本框中显示电子邮件?

2 个答案:

答案 0 :(得分:1)

<mx:TextInput text="{dg.selectedItem.Email}"/>

答案 1 :(得分:0)

您必须在DataGrid中设置editable="true"。如果您只想要“电子邮件”列可编辑,则可以这样执行:

<mx:Datagrid id="dg" dataProvider="{xmlData}" itemClick="editCell(event)">

功能:

public function editCell(event:ListEvent):void {
  dg.editedItemPosition = {columnIndex:1, rowIndex:event.rowIndex};
}