2012-05-07 28 views
0

我在移動Flex(4.6)應用程序中使用Spark Datagrid。當在網格中選擇一行時,我想觸發一個函數,並在同一個函數中使用所選項目的內容。這是我的DatagridFlex:在函數中使用DateGrid的selectedItem

<s:DataGrid id="patientGrid" x="317" y="211" width="393" height="177" 
      dataProvider="{patientInfo}" gridClick="patientSelect(event)"> 
    <s:columns> 
     <s:ArrayList> 
      <s:GridColumn dataField="FirstName" headerText="First Name"/> 
      <s:GridColumn dataField="LastName" headerText="Last Name"/> 
      <s:GridColumn dataField="DateOfBirth" headerText="Date Of Birth"/> 
      <s:GridColumn dataField="Gender" headerText="Gender"/> 
     </s:ArrayList> 
    </s:columns> 
</s:DataGrid> 

而當選擇一個項目時,患者選擇的功能需要能夠處理該選定項目的內容。

我希望我的問題很清楚,並感謝您的幫助!

回答

1

使用GridSelectionEvent.SELECTION_CHANGE事件,而不是出於兩個原因:

  • 將提供在哪些小區已選定的信息
  • 只要選擇更改(如果你只在鼠標點擊的反應,你不理它被觸發鍵盤導航/選擇)

<s:DataGrid id="dg" selectionChange="onSelectionChange(event)" /> 

private function onSelectionChange(event:GridSelectionEvent):void { 
    var index:int = event.selectionChange.rowIndex; 
    var patient = dg.dataProvider.getItemAt(index); 
    patientSelect(patient); 
} 
+0

頂部答案!得到它的工作,Thx! :) – Tommyke