2010-04-06 63 views
0

我已經創建了一個AdvancedDataGrid,其中大部分單元格基於一個ItemRenderer。自定義ItemRenderer(SoundBox)擴展VBox。此自定義組件允許基於用戶單擊單元格對背景顏色進行簡單更改。訪問多個ItemRenderer在一個AdvancedDataGrid中

這裏是在AdvancedDataGrid(沒有什麼太先進)的片段:

<mx:AdvancedDataGrid id="fsfw" dataProvider="{fsfWordList}" sortableColumns="false" > 
    <mx:groupedColumns> 
    <mx:AdvancedDataGridColumn width="35" dataField="wordcount" headerText=" "/> 
    <mx:AdvancedDataGridColumn id="myWord" width="150" headerText="TEST ITEMS"> 
    <mx:itemRenderer> 
     <mx:Component> 
      <components:SoundBox width="100%" letterSound="{data.word}" /> 
     </mx:Component> 
     </mx:itemRenderer> 
    </mx:AdvancedDataGridColumn> 
    <mx:AdvancedDataGridColumn width="200" headerText="Correct/2 points" dataField="sound1"> 
     <mx:itemRenderer> 
     <mx:Component> 
      <components:SoundBox width="100%" letterSound="{data.sound1}" pointColumn="2"/> 
     </mx:Component> 
     </mx:itemRenderer> 
    </mx:AdvancedDataGridColumn> 
    </mx:groupedColumns> 
</AdvancedDataGrid> 

我試圖做的是改變的背景顏色(讓我們只說我有一個數據行)ROW1,當用戶單擊row1的cell3時cell1爲綠色。

我不確定如何訪問網格中的這些項目(ItemRenderer/SoundBox)。

任何想法?謝謝!

回答

0

看看下面的代碼,,,它會返回給定行和colomn索引的item rendrer。擴展Advance dataGrid並在擴展類中定義這個函數,使它工作,然後像「CustomADG .indicesToItemRenderer(0,0)「,並在該reuturend對象中嘗試獲取對soundComponent的引用。

public function indicesToItemRenderer(rowIndex:int, colIndex:int):IListItemRenderer 
      { 
       var firstItemIndex:int = verticalScrollPosition - offscreenExtraRowsTop; 
       if (rowIndex < firstItemIndex || 
        rowIndex >= firstItemIndex + listItems.length) 
       { 
        return null; 
       } 

       return listItems[rowIndex - firstItemIndex][colIndex]; 
      } 
相關問題