2013-07-04 42 views
0

我正在處理一個正在從過程中獲取的變量中提取信息的數據網格。我需要能夠編輯overpaidAmount列。我已經鎖定了除了需要用戶輸入的列以外的所有列,但是一旦他們添加了信息,我該如何將它分配給變量?在網上隨處看,無法找到這個具體問題的任何東西。datagrid as3 - 如何將編輯後的單元格保存到變量

import fl.controls.DataGrid; 
import fl.controls.ScrollPolicy; 
import fl.data.DataProvider; 
import fl.controls.dataGridClasses.DataGridColumn; 

var col1:DataGridColumn = new DataGridColumn("Line"); 
var col2:DataGridColumn = new DataGridColumn("ServiceCode"); 
var col3:DataGridColumn = new DataGridColumn("BilledCharge"); 
var col4:DataGridColumn = new DataGridColumn("Paid"); 
var col5:DataGridColumn = new DataGridColumn("OverpaidAmount"); 

datagrid.addColumn(col1); 
datagrid.addColumn(col2); 
datagrid.addColumn(col3); 
datagrid.addColumn(col4); 
datagrid.addColumn(col5); 

col1.editable = false; 
col2.editable = false; 
col3.editable = false; 
col4.editable = false; 

col1.minWidth = 40; 
col2.minWidth = 80; 
col3.minWidth = 80; 
col4.minWidth = 80; 
col5.minWidth = 130; 

var myData:Array; 

if ((majorPercentage1 == "---") || (majorPercentage1 == "000") || (majorPercentage1 == " ")) 
{ 
    myData = 
    [ 
     {Line:"1", ServiceCode: cpt1, BilledCharge: charge1, Paid: basicPaid1, OverpaidAmount: overpaidAmount1}, 
     {Line:"2", ServiceCode: cpt2, BilledCharge: charge2, Paid: basicPaid2, OverpaidAmount: overpaidAmount2}, 
     {Line:"3", ServiceCode: cpt3, BilledCharge: charge3, Paid: basicPaid3, OverpaidAmount: overpaidAmount3}, 
     {Line:"4", ServiceCode: cpt4, BilledCharge: charge4, Paid: basicPaid4, OverpaidAmount: overpaidAmount4}, 
     {Line:"5", ServiceCode: cpt5, BilledCharge: charge5, Paid: basicPaid5, OverpaidAmount: overpaidAmount5} 
    ]; 
} 
else 
{ 
    myData = 
    [ 
     {Line:"1", ServiceCode: cpt1, BilledCharge: charge1, Paid: majorPaid1, OverpaidAmount: overpaidAmount1}, 
     {Line:"2", ServiceCode: cpt2, BilledCharge: charge2, Paid: majorPaid2, OverpaidAmount: overpaidAmount2}, 
     {Line:"3", ServiceCode: cpt3, BilledCharge: charge3, Paid: majorPaid3, OverpaidAmount: overpaidAmount3}, 
     {Line:"4", ServiceCode: cpt4, BilledCharge: charge4, Paid: majorPaid4, OverpaidAmount: overpaidAmount4}, 
     {Line:"5", ServiceCode: cpt5, BilledCharge: charge5, Paid: majorPaid5, OverpaidAmount: overpaidAmount5} 
    ]; 
} 
datagrid.dataProvider = new DataProvider(myData); 

任何幫助表示讚賞。

+0

此文檔可能有助於http://livedocs.adobe.com/flex/3/html/help.html?content=cell editor_8.html – Pan

回答

0

好了,所以我想出了一個解決方案,無論是做到這一點的最好辦法 - 也許不是:(

我不得不創建其持有從小區信息連續連用數動態文本字段然後我創建了一個輸入文本字段來顯示我想要更新的變量,添加了一個更新按鈕,其中包含下面的監聽器,並且這樣做了,只需要添加一些代碼來刷新數據網格,已更新。

function griditemselected (event:Event):void{ 
overPaid_txt.text = event.target.selectedItem.OverpaidAmount; 
} 

//Find the row number of the selected item so that we can update the correct overpaid amount 
datagrid.addEventListener(ListEvent.ITEM_CLICK , gridItemSelected); 
function gridItemSelected(e:ListEvent):void { 
rowID = Number(e.rowIndex)+1; 
}  

updated_btn.addEventListener(MouseEvent.CLICK, updateOverpaid); 

function updateOverpaid(e:MouseEvent):void 
{ 
//Update the selected line overpaidAmount  
switch (rowID) 
{ 
    case 1: 
    overpaidAmount1 = overPaid_txt.text; 
    break; 

    case 2: 
    overpaidAmount2 = overPaid_txt.text; 
    break; 

    case 3: 
    overpaidAmount3 = overPaid_txt.text; 
    break; 

    case 4: 
    overpaidAmount4 = overPaid_txt.text; 
    break; 

    case 5: 
    overpaidAmount5 = overPaid_txt.text; 
    break; 
}   
//Remove all the rows and refresh with new variable for overpaid amount 
datagrid.removeAll(); 
datagrid.addItem(event1); 
datagrid.addItem(event2); 
datagrid.addItem(event3); 
datagrid.addItem(event4); 
datagrid.addItem(event5); 
} 
相關問題